This topic describes how to ingest data from your iOS application into Log Service Mobile O&M Monitoring. Mobile O&M Monitoring provides real-time monitoring for issues such as application crashes and uses intelligent analysis to help you identify potential risks in your application efficiently and cost-effectively.
Prerequisites
You have created a Mobile O&M Monitoring application. For more information, see Add an application.
Step 1: Integrate the SDK
(Recommended) Integrate with CocoaPods
-
Add the following lines to your project's Podfile.
This topic uses AliyunLogProducer 3.1.14 as an example. For more information, see Aliyun Log iOS Release.
// Add the aliyun-specs source. source 'https://github.com/aliyun/aliyun-specs.git' // Add the CocoaPods source. source 'https://github.com/CocoaPods/Specs.git' pod 'AliyunLogProducer', '~> 3.1.14', :subspecs => ['CrashReporter'] -
Save the file and run the
pod install --repo-updatecommand. -
Open your project with the .xcworkspace file.
Integrate using the SDK files
-
After you unzip the SDK files, add the following frameworks to your project.
AliyunLogCore.framework, AliyunLogCrashReporter.framework, AliyunLogOT.framework, AliyunLogProducer.framework, and WPKMobi.xcframework.
-
In Other Linker Flags, add -Objc.
-
Add the following system dependency libraries.
The system dependencies that you need to link include
libz.tbd,libc++.tbd,SystemConfiguration.framework, andCoreGraphics.framework. Set the status for each to Required.
Step 2: Configure the SDK
-
Import the header file in the AppDelegate.m file of your project.
#import <AliyunLogProducer/AliyunLogProducer.h> -
Initialize the SDK in the
application:didFinishLaunchingWithOptions:method of the AppDelegate.m file.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. SLSCredentials *credentials = [SLSCredentials credentials]; credentials.endpoint = @"your endpoint"; credentials.project = @"your project"; credentials.accessKeyId = @"your access key id"; credentials.accessKeySecret = @"your access key secret"; credentials.instanceId = @"your instance id"; [[SLSCocoa sharedInstance] initialize:credentials configuration:^(SLSConfiguration * _Nonnull configuration) { // Enable crash reporting. configuration.enableCrashReporter = YES; // Enable lag monitoring. configuration.enableBlockDetection = YES; }]; return YES; }The following list describes the
SLSCredentialsandSLSCocoaclasses.-
SLSCredentials
The
SLSCredentialsclass defines key configuration fields.Type
Field
Example value
Description
Configuration parameters
instanceId
sls-****d60f
The ID of the application that you added in the Mobile O&M Monitoring console. For more information, see Get the application ID.
endpoint
https://cn-hangzhou.log.aliyuncs.com
The endpoint of the region where your Log Service Project is located. You must add the
https://prefix. For more information about how to obtain the endpoint, see Public endpoints.ImportantOnly public endpoints are supported.
project
sls-ayasls-demo
The Log Service Project associated with the application you added in the Mobile O&M Monitoring console. For more information, see Add an application.
Authentication parameters
accessKeyId
LTAI****eYDw
The AccessKey ID of the Log Service Project. For more information about how to obtain an AccessKey ID, see AccessKey pair.
accessKeySecret
lrRq****GOVM
The AccessKey secret of the Log Service Project. For more information about how to obtain an AccessKey secret, see AccessKey pair.
securityToken
124f****a369
The security token for the Log Service Project. This parameter is required if you use Security Token Service (STS) for authentication. For more information about how to obtain a security token, see AssumeRole.
-
SLSConfiguration
The
SLSConfigurationclass lets you configure additional parameters for SDK initialization.Type
Field/Method
Description
Configuration methods
enableCrashReporter
Specifies whether to enable crash reporting.
enableBlockDetection
Specifies whether to enable lag monitoring.
spanProvider
Customizes the resource and attribute information of spans.
Environment configuration
env
The environment of the application. The default value is
default.Set this parameter to
devfor development environments andprodfor production environments. -
SLSCocoa
The
SLSCocoaclass provides methods for configuring all parameters related to SDK initialization and user information.Category
Field/Method
Description
Singleton
sharedInstance
Obtains the SLSCocoa singleton.
Initialization
initialize:configuration:
Initializes SLSCocoa.
Credential update
setCredentials:
Updates the credentials. Credentials can be updated at runtime.
Configuration method
setUserInfo:
Updates user information.
-
-
To use temporary credentials from STS, provide values for credentials.accessKeyId, credentials.accessKeySecret, and credentials.securityToken. The following example shows how to update these credentials at runtime.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. SLSCredentials *credentials = [SLSCredentials credentials]; // The instanceId parameter is required. credentials.instanceId = @"your instance id"; // The following parameters are optional. credentials.endpoint = @"your endpoint"; credentials.project = @"your project"; credentials.accessKeyId = @"your access key id"; credentials.accessKeySecret = @"your access key secret"; [[SLSCocoa sharedInstance] initialize:credentials configuration:^(SLSConfiguration * _Nonnull configuration) { // Enable crash reporting. configuration.enableCrashReporter = YES; // Enable lag monitoring. configuration.enableBlockDetection = YES; }]; return YES; } // You can make the call after the related information is requested. - (void) updateSLS { SLSCredentials *credentials = [SLSCredentials credentials]; // (Optional) Update the AccessKey. credentials.accessKeyId = @"your access key id"; credentials.accessKeySecret = @"your access key secret"; // For an AccessKey obtained by using STS, you must configure the following parameter. credentials.securityToken = @"your access security token"; // (Optional) Update the Project and other information. credentials.endpoint = @"your endpoint"; credentials.project = @"your project"; [[SLSCocoa sharedInstance] setCredentials:credentials]; }
Step 3: Verify the integration
-
Write test code to simulate or trigger a crash.
[self performSelector:@selector(die_die)]; -
Restart the mobile client, and after about 2 minutes, you can view the crash information in the target LogStore on the Log Service console.
On the Custom Query page of the target mobile O&M monitoring instance, click Query/Analysis. If logs are displayed, this indicates that data has been successfully ingested. In the left navigation bar of the mobile O&M monitoring console, select Custom Query, select the target LogStore, set a time range, and then click the Query/Analysis button. If the total number of logs is greater than 0 and the query status is displayed as "Accurate Result", this indicates that crash information has been successfully reported to Log Service.