tencent cloud

IOS SDK Log Upload
Last updated: 2025-11-07 17:40:38
IOS SDK Log Upload
Last updated: 2025-11-07 17:40:38
This article introduces how to quickly get started with the iOS SDK of Cloud Log Service (CLS) to implement log upload. For more details on SDK usage, refer to the code repository tencentcloud-cls-sdk-ios.

Prerequisites

Create and obtain TencentCloud API key information (accessKeyId and accessKey). For key information acquisition, please visit API Key Management.
Please ensure the associated account has the appropriate SDK log upload permission.
Installed iOS development environment. For details, please see Apple Developer.

Installing the iOS SDK

1. Create an iOS project.
2. Import the header file.
#import <TencentCloudLogProducer.h>
3. In the project folder, create Podfile and enter the command to import the CLS iOS SDK dependency package.
pod 'TencentCloudLogProducer/Core', '1.1.2'

Request Parameters

Variable
Type
Required
Description
endpoint
String
Yes
Regional information. For completion, see the domain name in the Log upload via API Tab under available region.
secretId
String
Yes
TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission.
secretKey
String
Yes
TencentCloud API key information. For key information acquisition, please visit API Key Management. Please ensure the associated account has appropriate SDK log upload permission.
topicId
String
Yes
Log topic ID information.

Upload Example Code for Logs

In the project, you can use the following example code to implement log upload ability. Sample code:
It is not recommended to store TencentCloud API key information in plaintext in project code. You can dynamically obtain API key information through environment variables. For detailed operations, please see configure environment variables.
// Fill in domain information, see the domain name in the Log upload via API Tab at https://www.tencentcloud.com/document/product/614/18940?from_cn_redirect=1#.E5.9F.9F.E5.90.8D
NSString* endpoint = @"project's_endpoint";

// Fill in TencentCloud API key information. For key information acquisition, please visit: https://console.tencentcloud.com/cam/capi
// Please ensure the associated account has appropriate log upload permissions. For permission configuration, see https://www.tencentcloud.com/document/product/614/68374?from_cn_redirect=1#.E4.BD.BF.E7.94.A8-api-.E4.B8.8A.E4.BC.A0.E6.95.B0.E6.8D.AE
// It is advisable to obtain key information from environmental variables
NSString* accesskeyid = @"your_accesskey_id";
NSString* accesskeysecret = @"your_accesskey_secret";

// Set the topic ID for log upload, replace with your Topic ID
NSString* topic_id = @"your_topic";

LogProducerConfig *config = [[LogProducerConfig alloc] initWithCoreInfo:[endpoint] accessKeyID:[accesskeyid] accessKeySecret:[accesskeysecret];
[config SetTopic:topic_id];
[config SetPackageLogBytes:1024*1024];
[config SetPackageLogCount:1024];
[config SetPackageTimeout:3000];
[config SetMaxBufferLimit:64*1024*1024];
[config SetSendThreadCount:1];
[config SetConnectTimeoutSec:10];
[config SetSendTimeoutSec:10];
[config SetDestroyFlusherWaitSec:1];
[config SetDestroySenderWaitSec:1];
[config SetCompressType:1];
//If callback is null, it will not be called back
LogProducerClient *client; = [[LogProducerClient alloc] initWithClsLogProducer:config callback:nil];
Log* log = [[Log alloc] init];
[log PutContent:@"cls_key_1" value:@"cls_value_1"];
[log PutContent:@"cls_key_1" value:@"cls_value_2"];
LogProducerResult result = [client PostLog:log];

Conclusions

Through these steps, you can quickly use the Tencent Cloud CLS iOS SDK to complete log upload. If you encounter any issues, please contact us to get help.
Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback