Offline Push

Last updated: 2021-01-05 20:00:53

    Application Scenarios

    You can use the offline push feature to notify users upon the arrival of new messages even when the app is running in the background or the process has been killed. iOS devices use APNs for offline push, while Android users need to register for offline message callbacks.

    Instant Messaging (IM) supports Apple APNS push, Xiaomi push, Huawei push, Meizu push, Vivo push, OPPO push, and Google FCM push. The vendor channels used in the IM Demo are provided and maintained by TPNS in a unified manner. If you need to integrate the offline push feature, you can integrate the TPNS service or integrate the offline push service of the desired vendor:

    iOS APNs Push Notifications

    Push notification formats

    The preceding figure shows the examples of a one-to-one chat message and group chat message.
    For more information about iOS APNs push formats, see Push Formats.

    Basic APIs

    The following APIs must be called to support APNs. For more information, see iOS APNs Event Reporting:

    • Set the token.
    • Switch to the background and report unread messages.
    • Switch to the foreground and push notifications.

    Setting the Ext extension field

    In some cases, an app needs to set the Ext extension field for push based on specific circumstances to facilitate user operations such as redirect clicks. You can input it into the Ext field in TIMCustomElem, and during push, the IM backend will input the field into Ext. Please refer to Customizing Offline Message Attributes to customize the extension field.

    Setting push sounds

    In some cases, an app needs to set the push sound of a single message to alert the user. You can input the sound into the sound field in TIMCustomElem, and during push, the IM backend will input the field into Ext. Please refer to Setting Custom Push Alert Sounds.

    Android Offline Push

    Android 1.8.0 and later versions support separating services from processes. When the app process is killed, the service survives and can continue to receive offline push notifications. For more information about the relevant settings and configuration, see Android Offline Push.

    Sending Messages from the Backend

    For iOS, you can refer to Push Formats to set the display format of APNs push messages; for Android, you can refer to Offline Push OfflinePushInfo to set the display format.

    References