victorious
victorious

Reputation: 309

Turning off push notifications

Is there any way in iOS mobile application so that in the app itself we give a button to turn off push notifications from the app(I am using Swift language for programming). Any help will be really helpful.

Upvotes: 2

Views: 4962

Answers (5)

Sivajee Battina
Sivajee Battina

Reputation: 4174

Recommended approach: Try to handle this from the backend. It will be helpful in future time.

Solution: You can use unregisterForRemoteNotifications. This function is used to unregister all the notification from Apple Store. Again when you want to turn on push notifications, you can register using registerForRemoteNotifications

This is how you need to register/unregister if you don't know how to do that.

  UIApplication.shared.unregisterForRemoteNotifications()
  UIApplication.shared.registerForRemoteNotifications()

Upvotes: 2

Subhash Sharma
Subhash Sharma

Reputation: 745

You can manage it from your server side , create an API for it. Which is the best solution according to me. Else you can Unregister you device from APN or Open app settings and let user turn off it.

Upvotes: 0

Ashish Jain
Ashish Jain

Reputation: 91

You should implement disabling push notifications on the server side. Apple docs said that you should call

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

only if you will not provide notifications in app anymore. Link

In other hand, iOS8 provides API to open Settings.app, where user can disable notifications for your app using switch control. Usage sample:

if (&UIApplicationOpenSettingsURLString != NULL)
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];   

Upvotes: 0

Clown
Clown

Reputation: 183

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

Upvotes: 0

Varun Naharia
Varun Naharia

Reputation: 5388

You can remove/set device token from server on remote notification on/off toggle button

Upvotes: 1

Related Questions