Silent Remote Notifications in iOS

How do Silent Remote Notifications work

Apple has introduced a way to send push notifications to iOS devices, without notifying the user in any way. So the user won’t see a badge, hear a sound, etc.A use case for that would be to let the app fetch data in the background, so that when the user runs the app, their content will be up-to-date.Here’s a sample payload that uses a silent notification to let the app perform some sort of api call or what not:

{
    "pn_apns" : {
        "aps" : {
            "content-available" : 1,
            "customObject": {
              "customKey1": "value1",
              "customKey2": "value2"
            }
        }
    }
}

The content-available: 1 is the secret sauce here. Specifying that informs the OS that this is a silent push.

Capabilities & Limitations

  • The app will become active (running in the background) when the notification is received.

  • This type of notification will get received even if the app is running in the foreground (regular push notifications don’t usually go through the same handler in the app delegate).

  • If the app is suspended by the system, it will become active to allow to process the remote notification.

  • The app will have 30s to process any requests (downloads, api calls, etc.) until it needs to report back to the system that it’s done processing.

  • Apple recommends to not send more than 2-3 / hr.

  • NOTE #1: If the app was manually killed by the user (Double-Tap Home > Swip Up to Quit), then there’s no way to “wake up” the app to process the notification.

  • NOTE #2: If the silent push isn’t sent immediately, the system will postpone the app’s requests to lower priority queue. Which means that at a later point in time, that notification will make it to the user’s device.

  • NOTE #3: Even if the user doesn’t give push notification access, the app can still wake up and process the event: “The exciting new opportunity for app developers in iOS 8 is that Apple will now deliver “silent” pushes even if the user has opted out of notifications. Also, “silent push” is no longer just for Newsstand apps. Every app can take advantage of this ability to refresh content in the background, creating the most up-to-date, responsive experience possible, the moment the user opens the app.”

  • NOTE #4: “Users still have the ability to switch off your app’s ability to process a “silent push” by means of the “Background App Refresh” control. Even though Apple Push Notification service (APNs) will deliver a push marked “content-available” to your phone, the OS will not wake up your app to receive it, effectively dropping it on the floor. However, opting out of “Background App Refresh” is a lesser-known capability not directly associated with Notifications. You don’t access this preference in your Notifications Settings–it’s located under General > Background App Refresh screen.”

KB

👨🏻‍💻 Developer 👨🏻‍💼 Entrepreneur 👨🏻‍🎨 Indie Artist 📷 Photographer

https://karlboghossian.com
Previous
Previous

Getting Started with Crypto

Next
Next

How to mimic C#’s BinaryReader / BinaryWriter in C++