Is there a way to programmatically unregister a device for push notification?
Solution 1
[[UIApplication sharedApplication] unregisterForRemoteNotifications]
should be used, in Objective-C.
UIApplication.shared.unregisterForRemoteNotifications()
in Swift.
Solution 2
The push notifications are sent from your server... so you should implement such a method yourself and remove or disable the device in the database on your server where you store the active devices.
If you only disable them locally on your device your server will still send messages until you get notification from the feedback service.. which you should check...
Solution 3
For Swift 4 and above
UIApplication.shared.unregisterForRemoteNotifications()
You can call this method after a user logout that you will be sure that the next user to connect will have a unique device token.
Joe Aikman
Updated on June 05, 2022Comments
-
Joe Aikman about 2 years
Just wondering if this is actually possible. So I can stop all notifications kind of like how notification center has the option to stop all notification.
I don't believe this is possible, but wondering what you might think.
-
Aaron Brager over 11 years"You should call this method in rare circumstances only, such as when a new version of the application drops support for remote notifications."
-
mikemike396 over 11 yearsI am confused why you must only call this in rare circumstances?
-
Mike D over 11 yearsShouldn't it be
[UIApplication unregisterForRemoteNotifications]
since the question was tagged 'ios'? developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/… -
Tanner Semerad over 9 years@Pyraego.com, I learned the hard way not to use
unregisterForRemoteNotifications
. Calling it would at times put the app in a state where callingregisterForRemoteNotifications
would no longer work.