15

I'm trying to add push notification to my app. I need to know how to make the push notification popup appear. The popup I'm pertaining to is an alert view that has two choices, "allow" and "don't allow". It asks the user whether to allow the app to receive notifications and stuff or not.

I've tried deleting my app over and over again and advancing the time but nothing worked.

Also, in case the popup appears, how can I know if the user selected don't allow/ allow?

Sahil Kapoor
  • 11,183
  • 13
  • 64
  • 87
cessmestreet
  • 2,298
  • 3
  • 22
  • 42
  • Check out this http://stackoverflow.com/questions/12598955/track-user-choice-for-push-notification-allow-dont – HRM Oct 31 '13 at 07:42

2 Answers2

45

Resetting the Push Notifications Permissions Alert on iOS

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 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.

Source

Eran
  • 387,369
  • 54
  • 702
  • 768
  • Interesting remark from the official source: 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: (see 1 to 4 above) – Wirsing May 01 '14 at 17:10
  • works, but feeling too complicated... – jianpx Jul 10 '14 at 03:10
  • It seems that it doesn't require to turn the device off two times (any more?). Just skip step two and save some time :) – nburk Sep 26 '15 at 16:30
  • tried this on a iphone6 with 8.1 without luck. I didn't receive local notification nor remote notifications prompts again as expected (I did skip step2... – DevilInDisguise Nov 17 '15 at 20:30
  • helpful answer from Eran. https://developer.apple.com/library/ios/technotes/tn2265/_index.html#//apple_ref/doc/uid/DTS40010376-CH1-TNTAG42 – BhushanVU Aug 04 '16 at 15:52
11

Popup appears afrer you register your application for remote notifications. For example:

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

how can I know if the user selected don't allow/ allow?

Application objects calls two delegate's methods:

-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{

}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error
{
}

UPD: Here is tutorial on how to setup your app for push notifications: http://www.raywenderlich.com/32960/

Sviatoslav Yakymiv
  • 7,887
  • 2
  • 23
  • 43
  • i'm already registering for remote notification but the popup doesn't appear. Am I missing something? as for didFailToRegisterForRemotNotification i've learned that it also goes there when i run in the simulator because it doesn't support push notification. Is there a way to isolate the error? I only care about the "don't allow" error. Thanks. – cessmestreet Oct 31 '13 at 07:42
  • Can you log and error? And yes. The simulator does not support push notifications. – Sviatoslav Yakymiv Oct 31 '13 at 07:46
  • That's my problem. I don't know the error returned when the user clicked don't allow because i can't even display the popup. T_T – cessmestreet Oct 31 '13 at 07:47
  • You also should configure your app id on developer.apple.com for receiving remote notifications. – Sviatoslav Yakymiv Oct 31 '13 at 07:49
  • I've managed to display the popup one time only but when i clicked "don't allow" didFailToRegisterForRemoteNotifications wasn't called. How will i know if user clicked don't allow? – cessmestreet Oct 31 '13 at 10:02
  • While both answers are correct, I find this answer most useful. It should be the top answer. – Brian Whipp Feb 16 '17 at 01:43