Silent notifications
Silent notifications are notifications that do not display alerts or otherwise disturb the user. When a silent notification arrives, the application handing code runs in background without bringing the application to foreground. Currently, the silent notifications are supported on iOS devices with version 7 onwards. If the silent notification is sent to iOS devices with version lesser than 7, the notification is ignored if the application is running in background. If the application is running in the foreground, then the notification callback method is invoked.
Sending silent push notification
Prepare the notification and send notification. See Sending push notifications.
The three types of notifications supported for iOS are represented by constants DEFAULT, SILENT, and MIXED. When the type is not explicitly specified, the DEFAULT type is assumed.
To set the type in event source notifications, create notification object using the WL.Server.createDefaultNotification API and set type on the notification object:
notification.APNS.type = "DEFAULT" | "SILENT" | "MIXED";
See WL.Server.createDefaultNotification and WL.Server.notifyAllDevices APIs in WL.Server class.
If the notification is event source-based, the silent notifications are ignored if they arrive before the application registers the callback.
In Broadcast, Tag-based and Uni-cast notifications set the type while you create the notification object:
notification.APNS.type = "DEFAULT" | "SILENT" | "MIXED";
See WL.Server.sendMessage API in WL.Server class.
If the notification is silent, the alert, sound, and badge are ignored.
Handling silent push notifications in hybrid iOS application
In the JavaScript push notification callback method, we must do the following steps:
- Check the notification type. For example,
if(props['content-available'] == 1) { //Silent Notification or Mixed Notification. Perform non-GUI tasks here. } else{ //Normal notification }
- If the notification is silent or mixed, after you complete the background job, invoke WL.Client.Push.backgroundJobDone API. See WL.Client.Push class.
Handling silent push notifications in native iOS application
You must follow these steps to receive silent notifications:
- Enable the application capability to perform background tasks on receiving the remote notifications.
- Implement new callback method on AppDelegate (application: didReceiveRemoteNotification:fetchCompletionHandler:) to receive silent notifications when the application is running on background.
- In the callback, check whether the notification is silent or not by checking that the key content-available is set to 1.
- After finishing processing the notification, we must call the block in the handler parameter immediately. Otherwise, the app will be terminated. Your app has up to 30 seconds to process the notification and call the specified completion handler block.
Parent topic: Push notification