iOS Push Notifications: Part 7— Special Cases

Dmitrijs Beloborodovs
Citadele Bank Developers
4 min readMar 28, 2024

There is this saying “One more thing…” Here is push notifications’ version.

Photo by Hassan Sherif on Unsplash

Badge number

This is not directly linked with notifications. But still. Thing to remember that badge number survive app uninstall. Once app reinstalled, old value will pop up. Which is quite confusing to customers. Think through this scenario and find way to clean it up.

Shortcut into push settings

You can get into push notifications settings from push notification settings selecting View Settings.

Direct Link to Notifications inside App

When requesting push notifications permission add providesAppNotificationSettings

[.alert, .badge, .sound, .providesAppNotificationSettings]

That will add new button inside system preferences for your app

Which calls app delegate’s method

    func userNotificationCenter(
_ center: UNUserNotificationCenter,
openSettingsFor notification: UNNotification?
) {
// TODO: open push notifications settings screen
}

Removable notification

Sometimes you might need to delete already sent push. There are plenty of use cases when something expired and have no value. To do that you need send background push with “content-available”: 1 and, preferably, ID of a message to delete.

{
"aps": {
"content-available": 1
},
"deleteId": "1234"
}

Upon receiving background push, check for ID field, and delete notification:

func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any]
) async -> UIBackgroundFetchResult {
if let idToDelete = userInfo["deleteId"] as? String {
UNUserNotificationCenter.current().removeDeliveredNotifications(
withIdentifiers: [idToDelete]
)
}
return .noData
}

Low battery mode

Unless you are eligible to send critical alerts. When Low Power Mode enabled, your pushed will be silenced: no sound, no lighting up of the screen. You still be able to see in the list of notifications.

Push Notifications and Apple Watch

If a watch is paired and iPhone is locked, a push automatically transferred to watch. So, no sound played on iPhone.

Sire Reading Notifications

You may enable “Announce Notifications” for Siri.

Notifications will be announced when headphones attached or CarPlay connected.

Notifications Scheduled Summary

If you need a moment without disruption, you may enable Scheduled Summary. Go to Settings app → Notifications → Scheduled Summary.

Your app must be explicitly enabled to be included in summary.

Opening summary you may view more details.

If there is more than one app in summary, system will construct view dynamically.

I’ve also noticed that iOS cache app icon for this view. So, if you change your app icon, you still may observe old one in this summary view. 🤷‍♂️

Notification and Mobile Data

I observed following situation with a Skype a while ago. There were no WiFi available, only mobile network. App was not allowed to use mobile data. And it didn’t. If you try to refresh chat messages, you got error. Yet, since mobile network was allowed to system, Skype still received push notifications. Which proves notification is part of system, not app.

Sadly, I cannot reproduce this behaviour because there is a bug in iOS 17.4 (since iOS 16.2 if believe this) when app still use mobile network even it’s explicitly disabled. 🤷‍♂️

Privacy Concerns about Push Notifications

If you follow news, you might be hearing about this research. The idea is send background push, collect available data (may include battery level, location, if allowed, local time, locale, memory level, display brightness, phone model) and send to server. All of that without visible app launch.

Apple responded with this. 🤷‍♂️🤷‍♂️🤷‍♂️

Feel free to play with source code.

--

--