This guide shows you how to integrate and configure the Alibaba Cloud Mobile Monitoring SDK for iOS. It covers core procedures such as initializing the SDK, building your project, and verifying the integration.
Prerequisites
You have created an application in the EMAS console and obtained the required credentials.
Log on to the EMAS console.
Create an iOS application to obtain an AppKey, AppSecret, and AppRsaSecret.
For more information, see the quick start documentation.
Your development environment meets the following requirements:
Xcode 12.0 or later
iOS 10.0 or later
CocoaPods 1.12.0 or later
If your application already uses a version of the crash analysis, performance analysis, or remote log SDK earlier than 2.0.0, follow the iOS SDK Upgrade Guide to upgrade to the Mobile Monitoring SDK.
Demo projects
For sample integration projects for the Mobile Monitoring SDK for iOS, see the demo project (Objective-C) or the demo project (Swift).
Add the SDK to your app
Method 1: CocoaPods (Recommended)
Create or edit your Podfile:
source 'https://github.com/CocoaPods/Specs.git' source 'https://github.com/aliyun/aliyun-specs.git' platform :ios, '13.0' use_frameworks! target 'YourTarget' do pod 'AlicloudApmAll', '${ApmVersion}', :subspecs => [ 'AlicloudApmPerformance', 'AlicloudApmRemoteLog', 'AlicloudApmMemAlloc', 'AlicloudApmMemLeak', # 'AlicloudApmMemLeakSwiftSupport', # Optionally, include for Swift object support in memory leak detection. ] endImportantYou can find the
ApmVersionin the iOS SDK release notes.AlicloudApmAll component and dependency details:
The crash analysis component, AlicloudApmCrashAnalysis, is included by default and does not need to be explicitly declared.
Optional capabilities are provided as subspecs and can be included as needed:
Performance analysis: AlicloudApmPerformance
Remote log: AlicloudApmRemoteLog
Memory allocation: AlicloudApmMemAlloc
Memory leak: AlicloudApmMemLeak (AlicloudApmMemLeakSwiftSupport is an add-on for Swift memory leak detection.)
NoteIn the root directory of your Xcode project, locate and edit the Podfile to add the AlicloudApmAll dependency. You can run the
pod search AlicloudApmAllcommand to find the latest version. If a Podfile does not exist, run thepod initcommand in the project's root directory to create one. If you have not installed CocoaPods, first install it from the official CocoaPods website.Run the installation commands:
pod repo update AliyunRepo pod install # If you have not added the Alibaba Cloud CocoaPods repository, run the following command first to add it. # pod repo add AliyunRepo https://github.com/aliyun/aliyun-specs.git
Method 2: Manual
Download the latest SDK package from the quick start documentation.
Unzip the package and add the frameworks:
Drag the following .xcframework files into your project:
AlicloudApmAll.xcframework
AlicloudApmCore.xcframework
AlicloudApmCrashAnalysis.xcframework
AlicloudApmPerformance.xcframework
AlicloudApmRemoteLog.xcframework
AlicloudApmMemAlloc.xcframework
AlicloudApmMemLeak.xcframework
UTDID.xcframework
The figure below illustrates the required steps.
Add the following open-source library in the same way:
SSZipArchive: Download.
Navigate to Build Phases > Link Binary With Libraries and add the following built-in system libraries:
libc++.tbd
libz.tbd
libresolv.tbd
CoreTelephony.framework
SystemConfiguration.framework
Xcode compatibility
When using an earlier version of Xcode, you might need to manually add the following system libraries to ensure compatibility:
libz.tbd
libresolv.tbd
CoreTelephony.framework
SystemConfiguration.framework
Linker settings
If you encounter issues during runtime, try adding the -ObjC flag:
Open your Project Settings.
Navigate to TARGETS.
Select Build Settings.
Find the Linking section.
In Other Linker Flags, add -ObjC.
Use the SDK
1. Initialization
Initialize the SDK in your AppDelegate file. The following code shows an example:
#import "AlicloudApmCore/AlicloudApmCore.h"
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"
#import "AlicloudApmMemAlloc/AlicloudApmMemAlloc.h"
#import "AlicloudApmMemLeak/AlicloudApmMemLeak.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
EAPMOptions *options = [[EAPMOptions alloc] initWithAppKey:@"Your_AppKey"
appSecret:@"Your_AppSecret"];
options.appRsaSecret = @"Your_AppRsaSecret";
// The following sdkComponents correspond to crash analysis, performance analysis, remote log, memory allocation, and memory leak. Include as needed.
options.sdkComponents = @[[EAPMCrashAnalysis class], [EAPMPerformance class], [EAPMRemoteLog class], [EAPMMemAlloc class], [EAPMMemLeak class]];
[EAPMApm startWithOptions:options];
return YES;
}
@end
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let options = EAPMOptions(
appKey: "Your_AppKey",
appSecret: "Your_AppSecret",
// The following sdkComponents correspond to crash analysis, performance analysis, remote log, memory allocation, and memory leak. Include as needed.
sdkComponents: [CrashAnalysis.self, Performance.self, RemoteLog.self, MemAlloc.self, MemLeak.self]
)
options.appRsaSecret = "Your_AppRsaSecret"
EAPMApm.start(options: options)
return true
}
}
For applications developed in Swift, you also need to configure a Bridging-Header.h file and import the necessary SDK header files:

#import "AlicloudApmCore/AlicloudApmCore.h"
// The following header files correspond to crash analysis, performance analysis, remote log, memory allocation, and memory leak. Import them as needed.
#import "AlicloudApmCrashAnalysis/AlicloudApmCrashAnalysis.h"
#import "AlicloudApmPerformance/AlicloudApmPerformance.h"
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"
#import "AlicloudApmMemAlloc/AlicloudApmMemAlloc.h"
#import "AlicloudApmMemLeak/AlicloudApmMemLeak.h"
2. Build
In your project's Build Settings, set
Allow Non-modular Includes In Framework ModulestoYES.
Build the project.
NoteIf a
duplicate symbolerror occurs during the build, check if you have duplicate dependencies managed by both local files and CocoaPods. If so, remove the local dependency.If an
Undefined symbol: __swift_FORCE_LOAD_$_swiftCompatibility56error occurs during the build, go to Target > Build Settings > Library Search Paths and add the following path: $(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME).If you use other Alibaba Cloud products, a build failure may occur due to UTDID dependency conflicts. For a solution, see Resolve SDK UTDID Conflicts.
Integration verification
Run your app on a physical device or a simulator. Check the Xcode console for output similar to the following:
[AlicloudApmCore] Started Successfully
[AlicloudApmSetting] Fetched Successfully
These logs indicate that the SDK has started and fetched its configuration successfully.