iOS silent notifications

更新时间:
复制 MD 格式

iOS silent notifications

An iOS silent notification is a special type of remote push notification. Its purpose is not to display an alert to the user, but to synchronize data between an app running in the background and a server. For example, an app may have been in the background for a while. Its network connection is no longer active and its data may be outdated. The server can push a silent notification with parameters. The app, while in the background, can trigger a callback for the silent notification. This allows the app to retrieve the parameters and start a network request to fetch the latest data. This process is invisible to the user.

Limitations and notes:

  • Silent notifications are used to update and synchronize data without alerting the user. For this reason, silent notifications typically do not include content, sound, or a badge.

  • When a silent notification wakes a background app to perform a download task, the app has up to 30 seconds to complete the task.

  • The notification callback can be triggered when the app is in the foreground or background. The callback is not triggered if the app is closed.

  • The Apple Push Notification service (APNs) treats silent notification requests as low-priority tasks. Apple does not guarantee the delivery of silent notifications.

  • Do not use silent notifications to keep an app active. If APNs detects a high frequency of silent notification requests, it may stop sending them. Apple has not disclosed the specific policy.

Server-side configuration

Silent notifications typically do not include push content, sound, or a badge. The format of the payload sent to APNs is as follows. To mark the notification as silent, set content-available to 1.

{ 
"aps":{ 
"content-available":1 
}, 
"key1":"value1", 
"key2":"value2" 
}

To send silent notifications from the Mobile Push server, use the advanced push API of OpenAPI 2.0:

  • For more information, see Advanced push API.

  • Set iOSSilentNotification to True to enable silent notifications.

Client-side setup

Silent notifications trigger the didReceiveRemoteNotification callback.

To enable your app to process silent notifications in the background, modify your Xcode project:

  • In Xcode, select your app's project, and then select the app's target.

  • Open the Capabilities tab, enable Background Modes, and select Remote notifications.