Advanced version of push notification Part 1— UNAuthorizationOptions
This article is the advanced version of the push notification series. This article is going to cover mostly the notification authorization options. Before start this article please go through the previous articles
- How to configure iOS app to receive push notification
How to configure the iOS app to receive the push notification?
This article is the second part of the push notification series. If you haven’t seen what is the first part, it’s all…
2. How to generate authentication token/ push notification certificate to send push notification?
How to generate authentication token/Notification Certificate in AppStore connect for send push…
This is another article in push notification series. This article is going to explain how to generate the…
3. How to send push notification to real device without server configuration(for testing purposes)?
How to send notification to device without server configuration.
This article is another milestone article for the push notification series. This article is going to explain how to…
UNAuthorizationOptions is used when you are requesting authorization from the user for receiving the push notification. This section is going to cover what are the options available and how it’s used for.
When you request the push notification if you add this as an authorization option, apple will handle the badge for your notification(This value should be passed from the Notification payload), Badge indicate to the app how many notification received, but the number of counts should be pass from the payload app can’t handle by its self.
If you drag and drop the payload or send using the push notification app you will see the notification badge as above, But if you open the app and close the badge won’t get cleared. To clear the notification badge you should set the IconBudgeNumber as 0. UIApplication.shared.applicationIconBadgeNumber = 0
This option will ask the users to display the push notifications. This is based on the system setup the alert can be displayed as a banner or alert.
This option will play the sound if the push notification arrived on the device. By default, the notification plays the default sound, with the payload help we can pass the sound name from the remote and play it from the device. If the given sound is not found in the app, it will play the default sound.
Please note ⚠️
- The local notification sound length should be 30 sec or lesser than that
- If you play the longer notification sound users might get annoyed, So better think about some user experience when you have custom push notification sounds.
When we add this option in the push notification request permission, the push notification will be displayed in the Car Play also.
This is another option available in the push notification request permission. To support the critical alert, you must apply for a special entitlement from apple to enable them. Because these critical alerts will be displayed to the user even if the user declined the permission and if the app is in the do not disturb mode. Usually, this is used in health care, home security-related and other public safety-related apps.
Some people usually disabled the notification permission especially older people because there is not much information about what will be delivered and displayed to the user. So to work around, if we add these notification authorization options notification will automatically be added to the notification Center without asking for permission and there will be no sound or alert. Users who are looking at the notification Center will notice the notification and when they click the notification from that point they can allow or deny the notification permission.
Add this logic in the register notification function.
After did above code change run the app on real device, you should be able to get the device ID in the output console panel.
By using the device ID, now open the push notification app and send one push. you should be able to see the notification in the notification center.
From this place itself, you should be able to accept or reject the push notification. By clicking the Turn Off button you can ignore the notification received.
If you click the Keep button there will be another alert will be presented which contains two options.
- If you select Immediate Deliver when you receive the push notification next time it will be delivered immediately.
- If you select the Deliver in Schedule Summary based on your device/app set up on the schedule summary the notification will be delivered to you.
- This option is only available from iOS 12, so if your app is handling the previous iOS version you should handle that.
- These features can’t be tested in simulator, so after the code changes run the app on a real device you should be able to get the device token, by using that device token you can send the push notification using the push notification app.
This is the first part of the advanced notification with UNAuthorizationOptions, I’ll be writing another article for the notification payload. Keep in touch for the next article. I hope you guys learned new stuff from UNAuthorizationOptions what are those how it can be used what are the limitations. Let me know if you have any questions or suggestions to improve my article writing by adding comments in this article. Don’t forget to give me some claps 👏.
Check the latest code from this GitHub
GitHub - Achsuthan/iOSPushNotificationMediumArticle at AuthorizationOptions
You can't perform that action at this time. You signed in with another tab or window. You signed out in another tab or…
See you in the next article.