Make App Pie

Training for Developers and Artists

Add Provisional Permissions for Notifications

If you’ve worked with notifications before, you’ve probably dealt with user permissions. IN iOS 12, there’s a new type of user notification permission to handle a situation that happens often, which is super easy to add to already existent code.

Download the exercise file and you’ll find a project I adapted from chapter three of my Course Learning iOS Notifications . I tidied up the storyboard a bit and converted the file to iOS 12. Open up Xcode 10 with the project.

We need a clean simulator to show this correctly. Open up the simulator and choose an iPhone 8 plus. Click Hardware and Erase Content and settings..

and select Erase the content.

Head to the view controller and viewDidLoad . I have the notification permissions set here .

UNUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound]) { (granted, error) in
            self.isGrantedNotificationAccess = granted
            if !granted {
                //add alert to complain to user

I’ll run this with an iPhone 8 simulator, which is just a lot easer to navigate in a  I get the permissions message.

This is the current way to set up user permissions for notifications. Click Allow.

Click the Schedule  a Pizza and Make a Pizza button  a few times, which will send some notifications to your simulator. Wait a few seconds and You’ll see a notification.

Add a few more notifications. Press Command-L to lock the phone. The notification appears.

Press Home or  Commmand-Shift-H to go back into the app. Swipe down from the top to go to the notification center. You’ll see your notifications.

You’ll also the new iOS 12 feature of stacking when too many of the same type of notification appears, they stack to clean up your notifications. to see each nitrification, click the top one.

Swipe a notification to the one right again and you’ll have three choices.

View  view the notification in full and Clear clears it. Tap Manage.

The user can set notification preferences from any notification in iOS12. They can turn them off or change other settings. They also have one new mode: Deliver Quietly. This will display the notification only in the notification center. You won’t see the notification on a home screen or in a banner to interrupt you.

Stop the app, then erase the simulator’s content and settings. All of the above was to show you how notifications works under normal circumstances. The new permission state for notifications is the provisional state. This is a kind of sampler of notifications so users can decide if notifications are worth their time. There’s no permission question. Notifications default to deliver quietly instead of prominently. To add this functionality to your app, you add .provisional to your list of options for requesting authorizations. 

NUserNotificationCenter.current().requestAuthorization(options: [.alert,.badge,.sound,.provisional]){

Run this. Schedule a  few pizza and make a few  pizzas. You can wait a while either on lock or in the app, but you will see no notifications any where. Press home and the notifications are still not there. Open the notification center, and you’ll find your notifications.

Open the stack  and go to the first one, on the bottom of the stack.

On this notification the user decides if they want to turn off the notification.   The user can also tap keep to change the delivery method.

Going back to Deliver Prominently gives you banner notifications.

The Provisional Permissions option lets your user sample your notifications without a pesky permission question. With a single change to code you get a new functional you will want to use if your app uses notifications.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: