push-notificationios12

Setting application badge using provisional authorization in iOS 12


So iOS 12 introduced Provisional Authorization for Quiet Notifications that could be seen in Notification Center but not on the Lock screen. It has very cool advantage - you don't need user's approval to send one.

Several articles (smashingmagazine.com, gadgethacks.com, etc.) claim that iOS app will be able to set it's badge if received Provisional Authorization.

Is it really possible to set app badge when app is Provisionally Authorized?

I request authorization using code below:

[[UNUserNotificationCenter currentNotificationCenter]
     requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionProvisional
     completionHandler:^(BOOL granted, NSError *_Nullable error) {
       if (granted) {
         [[UIApplication sharedApplication] registerForRemoteNotifications];
       }
     }];

I receive token at didRegisterForRemoteNotificationsWithDeviceToken: that could be used to send Push Notification. When I send Push Notification with a payload {"aps":{"alert":"Testing..","badge":1}} I see it in Notification Center but app doesn't get badged.

I tried setting badge using UIApplication.sharedApplication.applicationIconBadgeNumber = 1; but it didn't work as well. It works though if I request regular authorization without providing UNAuthorizationOptionProvisional option.


Solution

  • Same issue here.

    It seems, that app badges are off by default for provisional authorization. I couldn't find anything about it in the documentation.

    But you can see it in the apps notification settings. The "Badges" switch is off by default:

    Notification Settings