What is Silent Push Notification? When does the device receive it?
Asked Answered
B

2

64

I want to clear my local notification in notification tray. For this to be implemented, I am thinking to use the silent push notification. So I want to confirm when the device receives it and which things I can do with it?

Bayless answered 18/4, 2016 at 13:10 Comment(0)
R
106

They can be used to inform the application of new content without having the user informed. Instead of displaying a notification alert, the application will be awakened in background (iOS does not automatically launch your app if the user has force-quit it) and application:didReceiveRemoteNotification:fetchCompletionHandler: will be called. You then have the opportunity to process any information transparently for the user :

  • Download some content
  • Synchronize some elements,
  • Inform the user directly within the application when he opens it back

Note that your time is limited to 30s.

To configure silent notifications

To support silent remote notifications, add the remote-notification value to the UIBackgroundModes array in your Info.plist file. To learn more about this array, see UIBackgroundModes.

<key>UIBackgroundModes</key>
<array>
    <string>remote-notification</string>
</array>

Configuring a Silent Notification

The aps dictionary can also contain the content-available property. The content- available property with a value of 1 lets the remote notification act as a silent notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app.

For a silent notification, take care to ensure there is no alert, sound, or badge payload in the aps dictionary. If you don’t follow this guidance, the incorrectly-configured notification might be throttled and not delivered to the app in the background, and instead of being silent is displayed to the user

Rabid answered 18/4, 2016 at 13:30 Comment(7)
Would it wake the app if it was force killed?Advantageous
Does the user still need to give permission for receiving these notifications?Cattegat
If the app is force closed then will iOS relaunch it for a silent push?Ablebodied
The user does not need to give permission for silent push. They do have to allow the Background Fetch preference though. If the app is force quit by the user a silent push will not launch the app in the background.Daw
How to awake the app if the user swipes up and killed the app. In Whatsapp sender can always receive double tick confirmation from the receiver (IOS). How???Pallid
Hi i did poc, if app was force killed also, silent push notification wake up it and run for 30sLineman
how to sent silent push notification into app is terminated?Bronchopneumonia
H
30

When you send a silent push notification and if app is suspended then the system wakes up or launches your app and puts it into the background running state before calling the method but if the app is killed by user manually then it will not wakeup.

application:didReceiveRemoteNotification:fetchCompletionHandler:

This method is called when you send a silent push notification and your app has up to 30 seconds of wall-clock time to perform the download or any other kind of operation and call the specified completion handler block. If the handler is not called in time, your app will be suspended.

If you want to send a silent push notification then your notification payload should be like this :

{
    "aps" = {
        "content-available" : 1,
        "sound" : ""
    };
    // You can add custom key-value pair here...
}
Harwill answered 18/4, 2016 at 13:28 Comment(9)
I believe the advice to include sound : "" is now obsolete - that was a way to work around a bug in an older version of iOS.Ceremony
so application:didReceiveRemoteNotification:fetchCompletionHandler gets called for silent notifications. What gets called for regular push notifications?Healthy
@Honey. Sorry for late responding. Same delegate method will called for normal push notification also till iOS 9. As from iOS 10, we have a new push notification handler methods. You can handle both push notification in below method for iOS 10.. - (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandlerHarwill
@Harwill Your line "if app is suspended or not running, then the system wakes up or launches your app and puts it into the background running state". Suspended is OK, but in not running scenario, i dont think system wakes or launched app.Deliberate
@RajanMaheshwari Yeah it will not work. I have updated thanks.Harwill
@Harwill didReceiveNotificationResponse is not used for silent notifications. Because there is nothing to respond to. It's silent, you never get to know it happened. That's only used if the user taps/interacts with a notification...Healthy
But in Whatsapp, a sender can always receive double tick confirmation irrespectively of the receiver (IOS) is swipe-up killed or in the background. So, it means Whatsapp is not using a silent push because if the app is swiped up killed, IOS don't wake the app for notification. They are using something else???Pallid
@Pallid WhatsApp has integrated VOIP service and uses PushKit framework, so when app receives a silent notification, application will launch in active mode if an app is killed and you will receive call in method.Harwill
@Harwill in iOS 13 Apple does not allow app using VOIP to do anything excep for calling, what Whatsapp and similar app do for this change?Kyoko

© 2022 - 2024 — McMap. All rights reserved.