LTS iOS SDK
If you need to collect and analyze user information on iOS, such as browser, browsing behavior, device, device exception, and network usage records, you can use this SDK to report logs to LTS in Objective-C and Swift.

This function is available for whitelisted users in regions CN North-Beijing4, CN East-Shanghai1, and CN South-Guangzhou. To use it, create a service ticket.
Transport Protocol
HTTPS
Prerequisites
- You have obtained the name of the region where LTS is deployed.
- You have obtained a project ID of your Huawei Cloud account. For details, see API Credentials.
- You have obtained the IDs of the target log group and log stream in LTS.
Version Updates
Version |
Download Addresses |
Verification File Download Address |
Description |
System |
---|---|---|---|---|
1.0.27 |
Optimized performance |
iOS 10 and Xcode 11 and later |
||
1.0.26 |
Optimized performance |
iOS 10 and Xcode 11 and later |
||
1.0.24 |
|
iOS 10 and Xcode 11 and later |
||
1.0.21 |
|
iOS 10 and Xcode 11 and later |
||
1.0.19 |
|
iOS 10 and Xcode 11 and later |
||
1.0.18 |
|
iOS 10 and Xcode 11 and later |
||
1.0.15 |
Released for the first time. Four APIs provided: initWithConfig, config, report, and reportImmediately |
iOS 10 and Xcode 11 and later |
Installing the iOS SDK
- Integrate the access SDK.
Method 1: Using CocoaPods
- Add the official CocoaPods repository to the Podfile.
source 'https://github.com/CocoaPods/Specs.git'
- Add dependencies to the Podfile.
pod 'LTSSDK' , '1.0.27'
- Run the following command on the device:
pod install --repo-update
Method 2: Manual integration- Decompress the downloaded SDK to a specified directory. Note: Decompress the package only.
- Add the decompressed xcframework static library to your project.
The xcframework static library to be imported must be in the same disk space as the workspace. If they are not in the same disk space, select Copy items if needed and Create groups to copy the xcframework library file to the workspace.
- Add the official CocoaPods repository to the Podfile.
- Perform initialization. For details about the parameters, see Table 4.
- Objective-C: example initialization code
// LTS parameter configuration LTSConfigParams *params = [[LTSConfigParams alloc] init]; // Mandatory parameters params.region = @"Region where LTS is deployed"; params.projectId = @"Project ID of the account"; params.groupId = @"LTS log group ID"; params.streamId = @"LTS log stream ID"; // Note: Hard-coded or plaintext AK and SK of the account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. params.accessKey = @"AK"; params.secretKey = @"SK"; // Optional parameters // params.url = @"url"; // params.cacheThreshold = 200; // params.timeInterval = 3; // params.reportWhenEnterBackgroundEnabled = YES; // params.reportWhenAPPLaunchEnabled = NO; // LTS initialization method LTSSDK *lts = [[LTSSDK alloc] initWithConfig:params];
- Swift: example initialization code
The LTS SDK supports multi-instance log reporting. Instances are created based on different configurations for reporting.
// LTS parameter configuration let params = LTSConfigParams() // Mandatory params.region = "Region where the LTS service is deployed" params.projectId = "Project ID of the account" params.groupId = "LTS log group ID" params.streamId = "LTS log stream ID" // Note: Hard-coded or plaintext AK and SK of the account for authentication are risky. For security, encrypt them. Decrypt them only when necessary. params.accessKey = "AK" params.secretKey = "SK" // Optional parameters // params.url = @"url"; // params.cacheThreshold = 200 // params.timeInterval = 3 // params.reportWhenEnterBackgroundEnabled = true // params.reportWhenAPPLaunchEnabled = false // LTS initialization method let lts = LTSSDK(config:params)
- Objective-C: example initialization code
- Report logs.
LTS provides two methods of reporting logs.
Table 2 Log reporting methods Method
Description
- (BOOL)report:(id)content labels:(nullable NSDictionary<NSString *, id> *)labels;
LTS stores logs in the local database and reports them in real time based on the configured policy.
- (BOOL)reportImmediately:(id)content labels:(nullable NSDictionary<NSString *, id> *)labels;
Logs are reported immediately.
Table 3 Parameters Name
Description
content
Log content. The value can be a dictionary or a dictionary array. A maximum of 300 outermost key-value pairs are allowed. The maximum length of a dictionary converted to a JSON string is 30,720 characters. If the length exceeds the maximum, the excess part will be truncated before being reported.
labels
Log labels. The value can be a dictionary or null. A maximum of 50 outermost key-value pairs are allowed. The maximum length of an outermost key is 64 characters. The key can contain letters, digits, and underscores (_), and must start with a letter. The maximum length of a dictionary converted to a JSON string is 30,720 characters. If the length exceeds the maximum, the excess part will be truncated before being reported.
- Objective-C code example:
//Report a single log. [lts report:@{@"content_key": @"content_value"} labels:@{@"label_key": @"label_value"}]; [lts reportImmediately:@{@"content_key": @"content_value"} labels:@{@"label_key": @"label_value"}]; //Report logs in batches. [lts report:@[@{@"content1_key": @"content1_value"}, @{@"content2_key": @"content2_value"}] labels:@{@"label_key": @"label_value"}]; [lts reportImmediately:@[@{@"content1_key": @"content1_value"}, @{@"content2_key": @"content2_value"}] labels:@{@"label_key": @"label_value"}];
- Swift code example:
//Report a single log. lts.report(["content_key": "content_value"], labels: ["label_key": "label_value"]) lts.reportImmediately(["content_key": "content_value"], labels: ["label_key": "label_value"]) //Report logs in batches. lts.report([["content1_key": "content1_value"], ["content2_key": "content2_value"]], labels: ["label_key": "label_value"]) lts.reportImmediately([["content1_key": "content1_value"], ["content2_key": "content2_value"]], labels: ["label_key": "label_value"])
- Objective-C code example:
Parameter Description
Parameter |
Type |
Mandatory |
Default Value |
Description |
---|---|---|---|---|
projectId |
NSString |
Yes |
- |
Project ID of the account. |
accessKey |
NSString |
Yes |
- |
AK of the account. A hard-coded or plaintext value is risky. Encrypt it for security and decrypt it only when necessary. |
secretKey |
NSString |
Yes |
- |
SK of the account. A hard-coded or plaintext value is risky. Encrypt it for security and decrypt it only when necessary. |
region |
NSString |
Yes |
- |
Region where LTS is deployed. |
groupId |
NSString |
Yes |
- |
LTS log group ID. |
streamId |
NSString |
Yes |
- |
LTS log stream ID. |
url |
NSString |
No |
nil |
Public network domain name address for reporting. The value can contain a port number, for example, https://lts-access.cn-north-4.myhuaweicloud.com:443. If no URL is set, a link is automatically generated based on the region. The format is as follows: https://lts-access.{region}.myhuaweicloud.com
|
cacheThreshold |
NSUInteger |
No |
200 |
When the number of logs stored in the local database reaches this threshold, an alarm is reported. Value range: 30 to 1000. |
timeInterval |
NSUInteger |
No |
3 seconds |
Interval for triggering reporting. Value range: 1 to 1800, in seconds. |
reportWhenEnterBackgroundEnabled |
BOOL |
No |
YES |
Whether to report logs when the app switches to running in the background. |
reportWhenAPPLaunchEnabled |
BOOL |
No |
NO |
Whether to report logs upon app startups. To enable this function, complete the configuration before the UIApplicationDidFinishLaunchingNotification notification is sent. |
Log Reporting Policies
This SDK supports the following log reporting policies: threshold-based reporting, scheduled reporting, reporting when the app is switched to the background, and reporting upon startup. Set parameters such as cacheThreshold, timeInterval, reportWhenEnterBackgroundEnabled, and reportWhenAPPLaunchEnabled based on the scenario.
Enabling Debugging
Enable debugging if needed. Then you can monitor log reporting in real time on the console, and make adjustments accordingly. Before initializing the LTS SDK, call the class method +(void)setLogLevel:(LTSLoggerLevel)logLevel to set the debug level, which can be Debug, Info, Warn, Error, or Off.
Objective-C code example:
#ifdef DEBUG [LTSSDK setLogLevel:LTSLoggerLevelDebug]; #endif
Swift code example:
#if DEBUG LTSSDK.setLogLevel(.debug) #endif
Obtaining Parameters
- Read the region table.
Table 5 Regions Name
Region
CN North-Beijing4
cn-north-4
CN East-Shanghai1
cn-east-3
CN South-Guangzhou
cn-south-1
- To obtain a log group's ID, choose Log Management in the navigation pane of the LTS console and hover over the target log group's name.
- To obtain a log stream's ID, click the down arrow on the left of the corresponding log group name to expand the log stream list, then hover over the target log stream's name.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot