Is there a way to programmatically unregister a device for push notification?

10,304

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.

Share:
10,304
Joe Aikman
Author by

Joe Aikman

Updated on June 05, 2022

Comments

  • Joe Aikman
    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
    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
    mikemike396 over 11 years
    I am confused why you must only call this in rare circumstances?
  • Mike D
    Mike D over 11 years
    Shouldn't it be [UIApplication unregisterForRemoteNotifications] since the question was tagged 'ios'? developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Referen‌​ce/…
  • Tanner Semerad
    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 calling registerForRemoteNotifications would no longer work.