8

I have used the following code to register my app to receive push notification, and I got the alert that asks me to register for push notification and I accidentally press cancel. Now I want to have the alert again so I can fire the delegate method in order to get the device token. But I don't get this alert any more and every time I open the settings I found that the notification is turned off for the app. I tried to delete the app from device, change app version, delete testing profile ,clean the target even I reset all the iPhone settings, but still was not able to solve this.I would very much appreciate any help, thanks

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     UIRemoteNotificationTypeBadge | 
     UIRemoteNotificationTypeAlert | 
     UIRemoteNotificationTypeSound];  

7 Answers 7

6

Apple's recommended way to reset the notification

During development only, of course.

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 following these steps:

Delete your app from the device. Turn the device off completely and turn it back on. Go to Settings > General > Date & Time and set the date ahead a day or more. Turn the device off completely again and turn it back on.

Don't forget to turn it off completely and back on.

3
  • 1
    Unfortunately, I haven't been able to get this to work in iOS 6. Apple's documentation appears to be wrong. Commented Oct 16, 2012 at 23:22
  • Same for me, had to completely reset (erase) the iPod touch on iOS 6 for the notification to reset - really painful.
    – Resh32
    Commented Nov 20, 2012 at 9:09
  • Apple modified their instructions and I've updated my answer with the update. It looks like the addition is that you need to restart completely after uninstalling the app. Commented Feb 2, 2014 at 4:57
3

Theres a notification option in the settings. Check out your application and turn on the notification from there.

I have learned somewhere that iOs 4 has this bug that it wont ask again even if youremove and reinstall the application.

Try Settings->Notifications-> your app-> Turn it on.

Hope it helps. Thanks

1
  • 1
    If I turned on the notification from the settings it won't call the mentioned code as it will find that the app is already enable for push notification and won't call delegate method - (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
    – Sarah
    Commented Jun 13, 2011 at 12:03
2

It seems like the question was never fully answered so here it is:

You can't make the built in prompt that actually changes the setting come up, but you can manually check if push notifications are currently enabled for your app and display your own alert if now. Here is what the function I use looks like:

+ (BOOL) arePushNotificationsEnabled 
{
    return [[UIApplication sharedApplication] enabledRemoteNotificationTypes] != UIRemoteNotificationTypeNone;
}
1

Resetting the Push Notifications Permissions Alert on iOS

For the first time a push-enabled applications, registers for push notifications. iOS asks the user if they wish to receive remote notifications for that particular app. Once the user has responded to this alert it is not presented again and 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 following these steps:

  1. Delete your app from the device.
  2. Turn the device off completely and turn it back on.
  3. Go to Settings > General > Date & Time and set the date ahead a day or more.
  4. Turn the device off completely again and turn it back on.

For more details check this out.

1
  • It works, the emphasis here is to turn off the device again after changing date. Commented Oct 28, 2015 at 8:45
0

Make sure you call this method at your AppDelegate's didFinishLaunchingWithOptions

 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
 UIRemoteNotificationTypeBadge | 
 UIRemoteNotificationTypeAlert | 
 UIRemoteNotificationTypeSound]; 

so that everytime the app will ask for Notifications

also check with your device settings to check notifications are turned on or not?

3
  • my notification setting is turned on in iPhone and I already call this code. But the iPhone remembers that I canceled the push notification alerts each time I run the app. And so I can not get the alert to enable notification again.
    – Sarah
    Commented Jun 13, 2011 at 12:06
  • 3
    dats y i told its a bug with iOs 4 and above... dont think it would be possible to do it Commented Jun 13, 2011 at 12:08
  • yeah maybe.. but u can give it a try :) Commented Jun 14, 2011 at 7:09
0

all you have to do is remove one of the notification methods from your register code and it will ask you again to allow notifications (for example remove UIRemoteNotificationTypeSound)

0
-1

To make our app ask it again and again.. call

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

first. Then call

 [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
 UIRemoteNotificationTypeBadge | 
 UIRemoteNotificationTypeAlert | 
 UIRemoteNotificationTypeSound]; 

Hope that helps. Thanks.

2
  • This doesn't actually work. Unregistering and reregistering doesn't ask the user any more than uninstalling and reinstalling does. Commented Oct 16, 2012 at 22:17
  • OK, if that does not work, what does work (programmatically)? Because if the user taps NO (on the allow alert), how can my app ask him again? Just re-registering (as mentioned) does not work. So what is the solution?
    – Gik
    Commented Nov 15, 2014 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.