Mobile application push development guide

更新时间:
复制 MD 格式

Follow this guide to configure mobile application services and develop push features for your proprietary app.

Prerequisites

  • You have set device alert rules on the Human-Computer Interaction page of product development in the console. For example, you can configure the system to push a message to the app when a door lock is opened or when the PM2.5 level exceeds 200. For more information, see Configure device alerting.

  • You have created a proprietary app. For more information, see Create a proprietary app.

Background information

Alibaba Cloud Mobile Push is a mobile push service with an online delivery rate of over 98%. It handled a peak message push rate of over 5,000 messages per second during the Double 11 shopping festival. For more information, see Mobile Push. The IoT Platform uses Alibaba Cloud Mobile Push and integrates device management capabilities to push device messages to your app.

Configure the mobile application push service

  1. Log on to the IoT Platform console.

  2. Select a project. On the project homepage, click the name of your proprietary app.

  3. Go to the SDKs and Plug-ins page of your proprietary app. Click Not Set for Message Push.

    image

  4. Configure the message push service for your iOS application.

    The push service for iOS applications does not distinguish between online and offline pushes. It uses the official Apple Push Notification service (APNs) that Apple provides to developers. Follow these steps.

    上传ios证书

    1. Click Upload File and upload the APNs push certificate.

    2. Enter the password for the push certificate and click Authenticate Certificate.

      The iOS push service can be called only after the certificate and password are correctly configured and successfully authenticated.

      验证证书

    3. Click Test Push. In the dialog box that appears, enter the deviceToken information. To obtain the deviceToken, see the didRegisterForRemoteNotificationsWithDeviceToken method in SDK Initialization.

    4. Click Test to push a test message.

      测试推送

  5. (Optional) Configure the offline push service for Android.

    Android applications support online push by default, and no extra configuration is needed. The platform also provides offline push capabilities for popular mobile devices, such as Huawei, Xiaomi, FCM, OPPO, and VIVO.

    image

    Note

    The following steps outline the general configuration process for third-party push services. The steps are for reference only. The actual procedure may vary depending on the third-party provider.

    • Huawei

      1. Register your app on the HUAWEI Developers website. After your app is approved, you will receive an AppID and AppSecret from Huawei.

      2. Enable the message push feature in the push section of the HUAWEI Developers platform.

      3. Add the message receipt webhook address on the HUAWEI Developers platform: https://amspush-ack.aliyuncs.com/hw/.

      4. On the Message Push Settings page in the IoT Platform console, configure the Huawei AppID and AppSecret.

      Important

      Make sure that you activate the push channel feature in the Huawei console and that your app status is Under Review or Approved. The channel does not work if the app is in a draft state.

    • Xiaomi

      1. Register your app on the Xiaomi Open Platform to obtain a Xiaomi AppID, AppKey, and AppSecret.

      2. Enable the message push feature in the push section of the Xiaomi developer platform.

      3. On the Message Push Settings page in the IoT Platform console, configure the Xiaomi AppSecret.

    • FCM (Google migrated GCM push to Firebase and renamed it FCM)

      Note

      Before you start, make sure that Google Play Services is installed on the mobile phone. Otherwise, the registration will fail. Most mobile phones in mainland China do not have Google services.

      1. Request and download the FCM service account private key file.

        • Create a project on the FCM push platform and add an app to the project.

        • Download the google-services.json file for the app. From the JSON file, retrieve the values of project_number and mobilesdk_app_id. Record them as sendId (used for SDK initialization) and applicationId (used for registration), respectively.image

        • In the Firebase console, go to Settings > Service accounts.

          image

        • Click Generate new private key, and then click Generate Key to confirm.

        • Securely store the JSON file that contains the key.

      2. Enter the FCM key into the IoT Platform.

        • Open the downloaded JSON file in a text editor.

        • Go to the IoT Platform. Copy the entire JSON content of the file and paste it into the GCM/FCM Server Key text box for the Production environment, as shown in the following figure.

        • The field may appear empty after you save. This is expected. Test whether a push can be sent successfully.

    • OPPO

      1. List your app on the OPPO marketplace. The app must have a rating of A to use the push service. For details about this policy, contact OPPO customer service.

      2. Register an OPPO enterprise developer account on the OPPO Open Platform to obtain an AppKey and MasterSecret.

      3. Add your application and enable the OPPO push service on the OPPO Open Platform.

      4. On the Message Push Settings page in the IoT Platform console, set your OppoAppkey and OppoMasterSecret.

    • VIVO

      Note

      VIVO push notifications are not currently supported in white-label apps on the Alibaba Cloud International site.

      1. Register a VIVO account and create an application on the VIVO Open Platform. You must use an enterprise developer account. After approval, you will receive an AppID, AppKey, and AppSecret for your application.

      2. On the Message Push Settings page in the IoT Platform console, set the AppID, AppKey, and AppSecret for your VIVO application.

Develop application push

Refer to the following SDKs to develop the mobile application push feature.

Pushable messages

The SDK provided by the IoT Platform supports the following two types of messages.

  • Device alert messages

    You can configure alert messages in the console. When a device triggers an alert rule, a message is automatically pushed to the app.

    Push scope: All users of the device, including the device administrator and users with whom the device is shared.

    Configuration method: Configure device alert information under Device Alerting on the Human-Computer Interaction page of the platform. For more information, see Configure device alerting.

  • Device sharing messages

    When the device administrator (ownerName, referred to as User A in the examples) shares the device with another user (memberName, referred to as User B in the examples), the platform automatically pushes a device sharing message to the app user.

    • ownerName: Device owner alias (for example, a username)

    • memberName: Shared user (or non-owner) alias (for example, a username)

    There are six types of device sharing messages. The following table provides examples of messages received during the device sharing process.

    Message type

    Device sharing scenario

    Device owner initiates sharing with another user

    When User A shares a device with User B, User B receives the message: ownerName + " shared a device with you.".

    Device owner cancels sharing

    When User A cancels sharing with User B, User B receives the message: ownerName + " canceled device sharing.".

    Shared user accepts the share request

    When User B accepts the share request from User A, User A receives the message: memberName + " added your device.".

    Shared user rejects the share request

    When User B rejects the share request from User A, User A receives the message: memberName + " canceled device sharing.".

    Device is preempted

    When User B preempts User A's device, User A receives the message: memberName + " preempted your device.".

    The initiator is detached.

    After User B accepts the shared device from User A, if User A detaches the device, User B receives the message: ownerName + " removed your device.".

    Note

    For Android applications, only the "Device owner initiates sharing with another user" message supports both offline and online push. All other device sharing messages support only online push.