How to enable/disable push notification from the app?

Jeff picture Jeff · Dec 11, 2012 · Viewed 36.9k times · Source

In my app I want to enable/disable push notification from the settings page of my app itself.Can any one suggest me a solution to turn on/off the status of app in notification center from the app ?

Answer

Paras Joshi picture Paras Joshi · Dec 11, 2012

you can register and unregister the remote notification with bellow code.

Register RemoteNotification with bellow code..means Enable notification

//-- Set Notification
if ([[UIApplication sharedApplication]respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    // For iOS 8 and above
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    // For iOS < 8
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

and Disable it with bellow code.

[[UIApplication sharedApplication] unregisterForRemoteNotifications];