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

IosApple Push-Notifications

Ios Problem Overview


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?

Ios Solutions


Solution 1 - Ios

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

Solution 2 - Ios

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...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSuhas Arvind PatilView Question on Stackoverflow
Solution 1 - IosPierre OleoView Answer on Stackoverflow
Solution 2 - IosArpitView Answer on Stackoverflow