iOS SDK upgrade guide

更新时间:
复制 MD 格式

This document describes how to replace the individual Crash Analytics, App Performance Analytics, and Remote Log Access SDKs with the all-in-one Alibaba Cloud App Monitor SDK.

Prerequisites

  • You have integrated one or more of the following products: Crash Analytics, App Performance Analytics, or Remote Log Access.

  • The top layer depends on the following frameworks.

    • Crash Analytics: AlicloudCrash, AlicloudApmCrashAnalysis

    • App Performance Analytics: AlicloudAPM

    • Remote Log Access: AlicloudTLog

Remove SDK dependencies

  1. Remove the existing SDK dependencies.

    target 'YourTarget' do
      # pod 'AlicloudCrash'            # Delete dependency
      # pod 'AlicloudApmCrashAnalysis' # Delete dependency
      # pod 'AlicloudAPM'              # Delete dependency
      # pod 'AlicloudTLog'             # Delete dependency
    end
  2. Run the installation command:

    pod install

Integrate the new SDK

Method 1: CocoaPods (Recommended)

  1. 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.
      ]
    end
    Important

    You can find the ApmVersion in 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.)

    Note

    In the root directory of your Xcode project, locate and edit the Podfile to add the AlicloudApmAll dependency. You can run the pod search AlicloudApmAll command to find the latest version. If a Podfile does not exist, run the pod init command in the project's root directory to create one. If you have not installed CocoaPods, first install it from the official CocoaPods website.

  2. 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

  1. Download the latest SDK package from the quick start documentation.

  2. Unzip the package and add the frameworks:

    1. Drag the following .xcframework files into your project:

      AlicloudApmAll.xcframework

      AlicloudApmCore.xcframework

      AlicloudApmCrashAnalysis.xcframework

      AlicloudApmPerformance.xcframework

      AlicloudApmRemoteLog.xcframework

      AlicloudApmMemAlloc.xcframework

      AlicloudApmMemLeak.xcframework

      UTDID.xcframework

    2. The figure below illustrates the required steps.

  3. Add the following open-source library in the same way:

  4. 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

Note
  • 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:

    1. Open your Project Settings.

    2. Navigate to TARGETS.

    3. Select Build Settings.

    4. Find the Linking section.

    5. In Other Linker Flags, add -ObjC.

Upgrade APIs

1. Crash Analysis

  • If your application depends on the AlicloudApmCrashAnalysis SDK, you do not need to upgrade the APIs.

Old API

New API

#import <AlicloudCrash/AlicloudCrashProvider.h>

/*!
* @brief Sets user information.
* @details Sets user information to be included when a crash occurs. The total data volume must be less than 10 Kb.
* @param key The key.
* @param value The value.
*/
+ (void)configCustomInfoWithKey:(NSString *)key value:(NSString *)value;
/**
 * Sets a key-value pair for a custom dimension.
 *
 * @param value The value.
 * @param key   The unique key.
 */
- (void)setCustomValue:(nullable id)value forKey:(NSString *)key;

/**
 * Sets multiple key-value pairs for custom dimensions in a batch.
 *
 * @param keysAndValues The key-value pairs.
 */
- (void)setCustomKeysAndValues:(NSDictionary *)keysAndValues;
/**
 * Sets a key-value pair for a custom dimension.
 *
 * @param value The value.
 * @param key   The unique key.
 */
func setCustomValue(value: Any?, forKey key: String)

/**
 * Sets multiple key-value pairs for custom dimensions in a batch.
 *
 * @param keysAndValues The key-value pairs.
 */
func setCustomKeysAndValues(keysAndValues: [String: Any])
#import <AlicloudCrash/AlicloudCrashProvider.h>

/*!
* @brief Reports a custom fault.
* @details Reports a custom fault.
* @param error The fault encapsulated as a standard NSError object.
*/
+ (void)reportCustomError:(NSError *)error;
/**
 * Records an exception object.
 *
 * @param error The exception object.
 */
- (void)recordError:(NSError *)error;

/**
 * Records an exception object.
 *
 * @param error The exception object.
 * @param userInfo Additional key-value pairs.
 */
- (void)recordError:(NSError *)error
           userInfo:(nullable NSDictionary<NSString *, id> *)userInfo;
/**
 * Records an exception object.
 *
 * @param error The exception object.
 */
fun record(error: NSError)

/**
 * Records an exception object.
 *
 * @param error The exception object.
 * @param userInfo Additional key-value pairs.
 */
func record(error: NSError, userInfo: [String: Any]?)
#import <AlicloudCrash/AlicloudCrashProvider.h>

/*!
* @brief Sets crash callback information.
* @details Sets crash callback information.
* @param crashReporterAdditionalInformationCallBack The returned dictionary cannot exceed 10 Kb. Do not perform time-consuming operations. Only strings are supported.
*/
+ (void)setCrashCallBack:(NSDictionary * (^)(NSString * type))crashReporterAdditionalInformationCallBack;
  • Not supported.

2. Remote Log Access

Old API

New API

// Old API example
#import <TRemoteDebugger/TLogBiz.h>
#import <TRemoteDebugger/TLogFactory.h>

+ (TLogBiz *)createTLogForModuleName:(NSString*)moduleName;
#import "AlicloudApmRemoteLog/EAPMRemoteLog.h"

+ (EAPMRemoteLog *)createLogForModuleName:(NSString*)moduleName;
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"

class func createLog(moduleName: String)
#import <TRemoteDebugger/TLogBiz.h>
#import <TRemoteDebugger/TLogFactory.h>

- (void)debug:(NSString *)message;
- (void)debug:(NSString *)message exception:(NSException *)exception;

- (void)info:(NSString *)message;
- (void)info:(NSString *)message exception:(NSException *)exception;

- (void)warn:(NSString *)message;
- (void)warn:(NSString *)message exception:(NSException *)exception;

- (void)error:(NSString *)message;
- (void)error:(NSString *)message exception:(NSException *)exception;
#import "AlicloudApmRemoteLog/EAPMRemoteLog.h"

/**
 * Records a debug level log.
 *
 * @param message The log content to record.
 */
- (void)debug:(NSString *)message;

/**
 * Records a debug level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
- (void)debug:(NSString *)message exception:(NSException *)exception;

/**
 * Records an info level log.
 *
 * @param message The log content to record.
 */
- (void)info:(NSString *)message;

/**
 * Records an info level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
- (void)info:(NSString *)message exception:(NSException *)exception;

/**
 * Records a warn level log.
 *
 * @param message The log content to record.
 */
- (void)warn:(NSString *)message;

/**
 * Records a warn level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
- (void)warn:(NSString *)message exception:(NSException *)exception;

/**
 * Records an error level log.
 *
 * @param message The log content to record.
 */
- (void)error:(NSString *)message;

/**
 * Records an error level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
- (void)error:(NSString *)message exception:(NSException *)exception;
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"

/**
 * Records a debug level log.
 *
 * @param message The log content to record.
 */
func debug(message: String)

/**
 * Records a debug level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
func debug(message: String, exception: NSException)

/**
 * Records an info level log.
 *
 * @param message The log content to record.
 */
func info(message: String)

/**
 * Records an info level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
func info(message: String, exception: NSException)

/**
 * Records a warn level log.
 *
 * @param message The log content to record.
 */
func warn(message: String)

/**
 * Records a warn level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
func warn(message: String, exception: NSException)

/**
 * Records an error level log.
 *
 * @param message The log content to record.
 */
func error(message: String)

/**
 * Records an error level log with an exception object.
 *
 * @param message The log content to record.
 * @param exception The exception object.
 */
func error(message: String, exception: NSException)
#import <TRemoteDebugger/TRDManagerService.h>

+ (TLogLevel)updateLogLevel:(TLogLevel)logLevel;
#import "AlicloudApmRemoteLog/EAPMRemoteLog.h"

+ (EAPMRemoteLogLevel)updateLogLevel:(EAPMRemoteLogLevel)logLevel;
#import "AlicloudApmRemoteLog/AlicloudApmRemoteLog.h"

class func updateLogLevel(logLevel: EAPMRemoteLogLevel) -> EAPMRemoteLogLevel

3. App Performance Analytics

Note

App Performance Analytics does not provide any APIs.