Disabling remote push notifications in app

I am trying to figure out what the best way is of implementing a "toggle notifications on / off" switch in iOS using the SwiftUI framework. Calling unregisterForRemoteNotifications() seems to be one solution, but it's not recommended, as I understand from the docs.

Another solution is to send a request to the provider server to set the token to inactive. But how would I handle this if the user happens to be offline when the toggle is switched, and comes online later? Any notificatins already sent would then arrive from APNs, I guess?

The user could disable notifications in systems settings, which I assume just mutes the notification on an iOS level? Is there a way to replicate this within the app itself? I understand that the user settings can't be manipulated directly. But what is the recommended way of handling this situation (if there is one)?

Thanks in advance!

You could implement a notification service extension to receive the push notifications, and request from Apple that they grant your app the com.apple.developer.usernotifications.filtering entitlement.

Set up a shared group between the app and the extension (i.e. to house shared defaults). When the user toggles on/off the switch the app writes that to the group defaults. When the extension receives a push, the extension reads the toggle switch setting from shared defaults and if the user has turned them off then the entitlement will enable the extension to suppress the displaying of the notification.

Thank you for the reply! As I understand, the filtering entitlement is meant for special use cases, and I don't think my case fits unfortunately. From what I can tell from other apps with similar functionality, the most common solution seems to be to just ignore the problem. Most apps seem to update user preferences in their backend, and if the user is offline, they simple aren't allowd to toggle notification on or off. To me, this seems like a frustrating solution. Another solution would be to store the preferences and then send them once the device has network connection again. But then you could still receive notifications that have been sent from the beckend while the device was offline, which would also be frustrating. I realie that this is probably a realtively small problem overall, but if you are making an app which is meant to be used in areas with unreliable network converage and has notifications as a central part of its functionality, it would be nice to have more control over this on a device level :)

Disabling remote push notifications in app
 
 
Q