Other Data Related Interfaces
Get User Identifier
By adding a 'User Identifier', you can retrieve specific user performance issues through the identifier on the Tingyun platform.
- Related Interface
/**
* Set the user identifier, should not exceed 256 characters, can be called multiple times at any position (value overrides)
* @userId: Unique information to identify a user
*/
+ (void)setUserIdentifier:(NSString *)userId;
- Code Example
- (void)viewDidLoad
{
[super viewDidLoad];
// he user identifier can be an email, phone number, or other information that can identify a user's identity, such as xxx@tingyun.com
[NBSAppAgent setUserIdentifier:@"userId"];
}
Enable Module Features on First Launch
For compatibility reasons, the SDK only enables all feature modules in debug mode on the first launch, and only the crash module in non-debug mode. You can enable the SDK's module switches through the following interface.
- Related Interface
/**
* The SDK is initialized for the first time without interaction with the Tingyun platform, so the default module switch only enables the 'Crash Module'. You can enable the 'Network Module' and 'User Experience Module' to collect data on the first launch of the application.
* @warning: Call this interface to set the startup options, the SDK's first launch is not controlled by the switches on the Tingyun platform
*/
+ (void)setStartOption:(NBSOPTION)option;
- Code Example
// Call before SDK initialization to enable network, crash collection, and user experience analysis on the first launch.
[NBSAppAgent setStartOption:NBSOption_Net|NBSOption_UI|NBSOption_Crash];
[NBSAppAgent startWithAppID:@"Your_appkey"];
Set Custom App Version Number
The SDK uses the application's 'CFBundleShortVersionString' as the version number by default. If you need to customize the version number, you can configure it by calling this interface before initializing the SDK.
- Related Interface
/**
* @brief Set the custom App version number, up to 64 characters, supports Chinese, English, numbers, and underscores
*/
+ (void)setVersionName:(NSString *)versionName;
- Code Example
int main(int argc, char * argv[]) {
@autoreleasepool {
[NBSAppAgent setVersionName:@"1.0.0"];
[NBSAppAgent startWithAppID:@"appkey" location:YES];
...
}
}
Get Tingyun Device ID
When the application is launched for the first time, the Tingyun server issues a deviceId to identify the device. Users can obtain the deviceId value through the interface.
- Related Interface
/**
* @return Returns the device ID generated by the Tingyun platform, which may be empty when first obtained
*/
+ (NSString *)getTingyunDeviceId;
- Code Example
- (void)getTyDeviceId
{
NSString *tyDid = [NBSAppAgent getTingyunDeviceId];
...
}
Set Geographic Location Information
You can set the latitude and longitude through the interface to accurately obtain the device's geographical location information.
- Related Interface
/**
* @brief Set latitude and longitude.
*/
+ (void)setLatitude:(double)latitude longitude:(double)longitude;
- Code Example
- (void)doSomething
{
...
[NBSAppAgent setLatitude:latitude longitude:longitude];
...
}
Compliance Configuration
In light of 'privacy and security' requirements that third-party SDKs need to be initialized after the user agrees to the 'privacy permissions', you can control the SDK's data transmission behavior through the 'Compliance Configuration' interface. It only takes effect on the first launch after installation.
- Related Interface
/**
* @brief Notify the SDK whether the user has agreed to the privacy agreement. It should be called at least once for each startup.
* @param agreement YES indicates that the user has agreed to the privacy agreement
* @discussion
* This interface should be used in conjunction with '+startWithAppID:launchImmediately:'; after the application is installed and launched for the first time, if launchImmediately: is set to NO, the SDK only collects data and does not initiate data upload requests until the agreement is set to YES; after the agreement is set to YES, the SDK will initiate a data upload request and upload the data collected before the agreement was set to YES.
* @warning Clearing the data in the sandbox Library/Cache/NBSCache directory may cause this function to malfunction, please proceed with caution.
*/
+ (void)setUserPrivacyAgreement:(BOOL)agreement;
- Code Example
int main(int argc, char * argv[]) {
NSString * appDelegateClassName;
@autoreleasepool {
[NBSAppAgent startWithAppID:@"APPKey" launchImmediately:NO];
appDelegateClassName = NSStringFromClass([AppDelegate class]);
}
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
- (void)getConsumerAgreement
{
...
if(agreement)
{
[NBSAppAgent setUserPrivacyAgreement:YES];
}
...
}
Get SDK Version Number
Get the current SDK version.
- Related Interface
/**
* @brief Get the SDK version number
*/
+ (NSString *)agentVersion;
- Code Example
NSString *sdkVesion = [NBSAppAgent agentVersion];
Enable SDK Log
After calling the interface, you can print SDK INFO logs.
- Related Interface
/**
* @brief Whether to enable embedded control console logs, default is off.
*/
+ (void)setLogEnable:(BOOL)enale;
- Code Example
[NBSAppAgent setLogEnable:YES];
[NBSAppAgent startWithAppID:@"Your_appkey"];
Set Business Line Name
Using the 'Set Business Line' interface, you can distinguish crashes, stutters, and network errors by business line to view specific business performance data.
- Related Interface
/**
* @brief Set the current business line, the same key value will override, keeping the latest value
* @params businessLine Business name, up to 256 bytes in length
* @params key Fixed as bname
*/
+ (void)setBusinessLine:(NSString *)businessLine forKey:(NSString *)key;
- Code Example
- (void)shoppingCar
{
[NBSAppAgent setBusinessLine:@"Shopping Cart" forKey:@"bname"];
}