Reputation: 309
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
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
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
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
Reputation: 183
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
Upvotes: 0
Reputation: 5388
You can remove/set device token from server on remote notification on/off toggle button
Upvotes: 1