Provisional Push Notifications in Swift

Payal Kandlur
3 min readApr 27, 2021

--

What are provisional notifications?

Provisional push notifications are notifications sent silently to the user’s notification center, without sounds or appearing as a banner on the user’s home screen.

Publishers can start sending them as soon as a user has downloaded and run your app for the first time, provided the app is registered for push notifications. Provisional push notifications can be sent indefinitely unless the user explicitly turns them off.

Prior to the release of iOS 12, publishers had one chance to obtain permission to send push through the native APN prompt.

Provisional push enables publishers to send notifications to a user’s device without explicitly obtaining prior permission (that is, no permission prompt appearing on the screen at any time!🥳). These notifications are used to give users a preview of the type of content sent via push notifications before deciding whether they want to receive them in the foreground.

Implementing Provisional Push Notifications

All that is required, is that you add the .provisional property of type UNAuthorizationOptions to the options argument in the call to requestAuthorization(options:completionHandler:).

After the provisional property has been added, all notifications will go to the Notification Center on the device, and will no longer appear on the device’s background or lock screen, as before. Also, the notification permissions prompt will not appear.

So what happens to the banner and sounds, how do we get that?

Once the user interacts with the notification, they will then receive the option of whether to keep or turn off notifications from this particular app.

If they opt in to keep receiving notifications, they will be able to choose whether to have them as overt (the normal ones with banner and sound😋) push notifications — Deliver Prominently — or to continue coming in quietly through the Notification Center — Continue Delivering Quietly.

The Special foreground condition for provisional notifications!😯

Once you trigger a notification, you may observe that the notification appears only when the app is not in the foreground.

That’s right, provisional notifications appear in your notification center only when the app is either in the background or inactive (that is basically not in the foreground!👀)

Handling provisional notifications in the foreground is something you should not miss and here's how you could do it!

We will be using the UNUserNotificationCenterDelegate and implementing userNotificationCenter:willPresentNotification:

Here you just need to add the presentation options, and your provisional notification will appear on the Notification Center only (🤔check the note below!).

Note: If the user has not selected the “Deliver promptly” option or changed the notification settings to allow for sound or banners, the provisional notification would still appear in the Notification Center and not as a banner even if the app is in the foreground.

That's all about it!💃 Feel free to drop your comments, questions and suggestions if any!😊

--

--

No responses yet