Simply pass the
content_available: true
parameter in the Send Notifications API request body and omit the notification
object to send a silent notification: {
"to": "a6345d0278adc55d3474f5",
"data": {
"silentPayloadData": "Hello World"
},
"content_available": true
}
Note: Silent notifications require the Background Modes -> Remote Notifications capability to be enabled in the Xcode project settings.
Additional Note: Due to Apple platform restrictions, silent notifications will not be delivered to your app if it has been swiped away from the recent apps / killed. If you'd like notifications to be received in this scenario, please consider sending regular (non-silent) iOS notifications, without the
content_available: true
flag.Furthermore, Apple restricts the number of silent notifications you can send to a device in a given day to about 5. Sending too many to the same device in a single day, or sending them in quick succession, will lead to those notifications being throttled (and dropped) by APNs.
Sending a silent notification will silently invoke your
pushy.setNotificationHandler()
even when your app is in the background:// Handle push notifications pushy.setNotificationHandler({ (data, completionHandler) in // Print notification payload data print("Received notification: \(data)") // Consume your custom payload in the background silently if data["silentPayloadData"] {
print("This is a silent notification") }
// Call this completion handler when you finish processing // the notification (after fetching background data, if applicable) completionHandler(UIBackgroundFetchResult.newData) })
You may execute a network request at this time to fetch additional data, and afterwards, display a local notification if you wish.
Comments
0 comments
Please sign in to leave a comment.