目录

1. Scenario Description

HUAWEI Push Kit provides the capability of sending messages to iOS apps via Apple Push Notification service (APNs), which is referred to as the iOS push agent in this document.

2. Preparations

Currently, AppGallery Connect does not support iOS apps. To use the iOS push agent, you need to configure it through an Android app. But before that, you need to register as a developer and create an Android app. For details, please refer to the Preparations for Android apps.

To use the iOS push agent, you need to create the required credentials and certificates on the Apple Developer website, including Identifiers, Keys, Certificates, download the certificates, add your keychain, and export the .p12 file. In addition, you need to obtain the device token for your iOS app, which will be used to send messages to the designated iOS device. For details, please refer to the guides provided by Apple Developer. For other preparations, please refer to the following.

2.1 Enabling the iOS Push Agent

After enabling HUAWEI Push Kit, enable the iOS push agent.

2.2 Setting iOS Push Agent Parameters

After enabling the iOS push agent, upload the APNs authentication key or certificate that you have applied for on the Apple Developer website.

1.  Upload your APNs authentication key.

2. Upload your APNs certificate. You can upload multiple certificates.

3. Development Guide

You can push messages to iOS apps by referring to the server sample code. The value of the token parameter in the message body should be your iOS device token. For more iOS related parameters, please refer toSending Messages.

Sample code:

  1. {
  2.    "validate_only": false,
  3.    "message": {
  4.        "notification": {
  5.            "title": "message title",
  6.            "body": "message body"
  7.        },
  8.        "apns": {
  9.            "headers": {
  10.                "apns-topic": "hmspush",
  11.                "apns-priority": "5"
  12.            },
  13.            "hms_options": {
  14.                "target_user_type": 1
  15.            },
  16.            "payload": {
  17.                "aps": {
  18.                    "alert": {
  19.                        "title": "ios message title",
  20.                        "body": "ios message body",
  21.                        "action-loc-key": "PLAY"
  22.                    },
  23.                    "badge": 5
  24.                },
  25.                "acme1": "bar",
  26.                "acme2": [
  27.                    "bang",
  28.                    "whiz"
  29.                ]
  30.            }
  31.        },
  32.        "token": [
  33.            "your IOS token"
  34.        ]
  35.    }
  36. }