Mobile Application Push SDK

更新时间:
复制 MD 格式

Alibaba Cloud Mobile Push is a mobile cloud service that uses big data technology. You can add mobile push features to your app to send efficient, precise, and real-time push notifications. This service reduces development costs and increases user activity and retention rates.

Dependent SDKOverview
API channelProvides API channel features and basic environment configuration.

Configure the service

The features in this SDK depend on the Alibaba Cloud Mobile Push service. You must configure the service in the console before you use these features. For more information, see Mobile Application Push Developer Guide.

Note Apple released iOS 13 in September 2019. To ensure that the Mobile Push feature works correctly, immediately update to the latest version of the software development kit (SDK) (pod 'AlicloudPushIoT', '1.9.5.5').

Initialization

To initialize the SDK, see SDK Initialization.

Usage

  1. Set up APNs with Apple.
    The APNs token is requested during SDK initialization. No extra steps are required.
  2. Listen for push notifications.
    /*
     *  Callback for when a notification is opened while the app is running.
     */
    
    - (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo {
        NSLog(@"Receive one notification.");
        // Get the APNS notification content.
        NSDictionary *aps = [userInfo valueForKey:@"aps"];
        // Content
        NSString *content = [aps valueForKey:@"alert"];
        // Badge number
        NSInteger badge = [[aps valueForKey:@"badge"] integerValue];
        // Play sound
        NSString *sound = [aps valueForKey:@"sound"];
        NSLog(@"content = [%@], badge = [%ld], sound = [%@]", content, (long)badge, sound);
        // Clear the iOS badge.
        application.applicationIconBadgeNumber = 0;
        // Report that the notification was opened.
        [[IMSIotSmart sharedInstance] application:application didReceiveRemoteNotification:userInfo];
    
    }          

    The SDK initialization code handles the logic for the following actions. No additional operations are required.

    • Associate Mobile Push with an account

      When a user logs on, the app automatically associates Mobile Push with their account. This action uses the /uc/bindPushChannel API service.

    • Disassociate Mobile Push from an account

      When a user logs off, the app automatically disassociates Mobile Push from their account. This action uses the /uc/unbindPushChannel API service.

Alerting feature

The alerting feature depends on user-device binding. This binding is included in the SDK initialization. Therefore, you only need to focus on the business logic for the alerting feature.