Enable or Disable iPhone Push Notifications Inside the App

Enable or Disable Iphone Push Notifications inside the app

First thing is that you can not enable and disable push notification in inside the app. If you have found some apps which did it than there must be workaround solution.

Like if you want to do Inside the app then use one identifier and send it to server according push notification enable and disable button. So, your server side coding use this identifier and work according to that. Like identifier is say it's enable than your server will send notification otherwise not.

You can check that user set enable or disable Push Notifications using following code.

Enable or Disable Iphone Push Notifications

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types == UIRemoteNotificationTypeNone)
// Yes it is..

Hope, this will help you..

Enable/Disable Apple Push Notification from iPhone app?

Unfortunately you can't enable or disable the Push Notifications for your app from the app code. The dialog asking for permission is displayed only once.
Usually, other apps display instructions to the user to enable / disable push notifications by going into Settings-> Notification-> AppName.

Enable/Disable push notification after did finish launch or inside our app

You should not use unregisterForRemoteNotifications, it will unregister APNS completely as apple said

You should call this method in rare circumstances only, such as when a
new version of the app removes support for all types of remote
notifications. Users can temporarily prevent apps from receiving remote notifications through the Notifications section of the Settings app.

here is link

It will be better if you implement disabling push notifications on your server side. Just told your server guy to make service to not send APNs.

or you can also open notifications section of the settings app as below

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

How to enable/disable push notification from my app

If a user denied permissions for push notifications you can not let him enable it from within the app.

You could however, set a button in your settings app (ViewController), and let the user switch the notifications off and on there. Then you can set a boolean to check before sending notifications. This way a user might use it instead of disabling the app's notification permission on the device settings.

How to correctly disable/enable push notifications

According to docs for unregisterForRemoteNotifications:

You should call this method in rare circumstances only, such as when a
new version of the app removes support for all types of remote
notifications. Users can temporarily prevent apps from receiving
remote notifications through the Notifications section of the Settings
app. Apps unregistered through this method can always re-register.

The correct way (actually the way I have seen in the projects I have worked on) is to call an api and tell the backend that push notification should not be sent.

How to enable/disable push notification from the app?

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];

Push Notification ON or OFF Checking in iOS

If the App once got registered with the registerForRemoteNotification, then you can disable as well as enable . Once you disable and you are about to Re-Regigister with it, then this will enable the registerForRemoteNotification, without Popup for a alert.

Technical Note TN2265: Troubleshooting Push Notifications

The first time a push-enabled app registers for push notifications, iOS
asks the user if they wish to receive notifications for that app. Once
the user has responded to this alert it is not presented again unless
the device is restored or the app has been uninstalled for at least a
day.

If you want to simulate a first-time run of your app, you can leave
the app uninstalled for a day. You can achieve the latter without
actually waiting a day by setting the system clock forward a day or
more, turning the device off completely, then turning the device back
on.

Fore More Info: INFO && Info 2

Edit : For checking with alert enable -

use

 if (types & UIRemoteNotificationTypeAlert){} 

instead of

if (types == UIRemoteNotificationTypeNone){}

Edit :
Latest update from the doc for iOS 8 or later, You can check out by :

- (BOOL)isRegisteredForRemoteNotifications


Related Topics



Leave a reply



Submit