This document describes the basic APIs for the iOS SDK. These APIs allow you to initialize the SDK, manage debug logs, retrieve the SDK version number, check the message channel status, and retrieve the push device ID.
Set the log level
During development, you can enable detailed SDK log output to help you identify and resolve issues. Before you publish your application, disable this feature to ensure optimal performance and security.
Log level definition
typedef NS_ENUM(NSInteger, MPLogLevel) {
MPLogLevelNone = 0,
MPLogLevelError = 1,
MPLogLevelWarn = 2,
MPLogLevelInfo = 3,
MPLogLevelDebug = 4
};API definition
+ (void)setLogLevel:(MPLogLevel)level;Code example
CloudPushSDK.setLogLevel(MPLogLevel.info);[CloudPushSDK setLogLevel:MPLogLevelInfo];Initialize the SDK
Initialize the SDK with yourappKey andappSecret. After initialization is complete, you can use the callback function to confirm the result.
API definition
+ (void)startWithAppkey:(NSString *)appKey
appSecret:(NSString *)appSecret
callback:(CallbackHandler)callback;Parameters
Parameter | Type | Required | Description |
appKey | NSString | Yes | Mobile Push service AppKey |
appSecret | NSString | Yes | The appSecret of the Mobile Push service. |
callback | Block | No | The callback function for the initialization status. |
Code example
CloudPushSDK.start(withAppkey: "Your AppKey", appSecret: "Your AppSecret") { res in
if res.success {
print("SDK initialized successfully | DeviceID: \(CloudPushSDK.getDeviceId() ?? "N/A")")
} else {
print("Initialization failed: \(result.error?.localizedDescription ?? "Unknown error")")
}
}[CloudPushSDK startWithAppkey:@"Your AppKey"
appSecret:@"Your AppSecret"
callback:^(CloudPushCallbackResult *result) {
if (result.success) {
NSLog(@"SDK initialized successfully | DeviceID: %@", [CloudPushSDK getDeviceId]);
} else {
NSLog(@"Initialization failed: %@", result.error);
}
}];Get the SDK version number
You can retrieve the current SDK version number by calling the following API or using the MPUSH_IOS_SDK_VERSION macro.
API definition
+ (NSString *)getVersion;Query the message channel status
You can check whether the push channel in your application is open.
API definition
+ (BOOL)isChannelOpened;Device ID
After the SDK is successfully initialized, you can call the following API to retrieve the device ID. The device ID is a unique identifier for the device within your application. The ID may change in certain cases, such as after an iOS system upgrade or a device reset.
API definition
+ (NSString *)getDeviceId;(Deprecated) Turn on debug logs
During development, you can enable detailed SDK log output to help you identify and resolve issues. Before you publish your application, disable this feature to ensure optimal performance and security.
API definition
+ (void)turnOnDebug;(Deprecated) Automatic SDK initialization
This method does not require you to configure the appKey and appSecret. Instead, it uses the AliyunEmasServices-Info.plist configuration file.
API definition
+ (void)autoInit:(CallbackHandler)callback;Parameters
Parameter | Type | Required | Description |
callback | Block | No | The callback function for the initialization status. |
(Deprecated) Manual SDK initialization
You can initialize the push SDK by providing the appKey and appSecret.
API definition
+ (void)asyncInit:(NSString *)appKey
appSecret:(NSString *)appSecret
callback:(CallbackHandler)callback;Parameters
Parameter | Type | Required | Description |
appKey | NSString | Yes | Mobile Push service AppKey |
appSecret | NSString | Yes | The appSecret of the Mobile Push service. |
callback | Block | No | The callback function for the initialization status. |
(Deprecated) Close the push message channel
You can close the push message channel, which is a long-lived connection. Make sure to call this API before you initialize the SDK.
API definition
+ (void)closeCCPChannel;