Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 783
Ruslan Mansurov Avatar asked Oct 05 '18 01:10

Ruslan Mansurov


People also ask

What is provisional permission iOS?

Use provisional authorization to send notifications on a trial basis. Users can then evaluate the notifications and decide whether to authorize them. The system delivers provisional notifications quietly—they don't interrupt the user with a sound or banner, or appear on the lock screen.

Can PWA push notifications in iOS?

Nope, Apple does not allow push notifications on iOS.

Does Safari support push notification?

When important, time-sensitive events occur, inform your website users with push notifications you send from your server. In Safari 16 in macOS 13 or later, Safari supports web push — push notifications that use the cross-browser Push API, Notifications API, and Service Worker standards.


1 Answers

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

like image 144
Zaggo Avatar answered Nov 15 '22 01:11

Zaggo