15

enter image description here

I was able to show an Alert View like the image above after registering for Remote Notifications. But when i delete my Project App and build it again, it will not show anymore.

Will there be any chances to show the alert view again to the same device?

What i like is to get my device token again because I failed to store the device token temporarily in the NSUserDefaults.

Vincent Bacalso
  • 2,071
  • 4
  • 23
  • 34

5 Answers5

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

reference: https://developer.apple.com/library/ios/technotes/tn2265/_index.html

user2387149
  • 1,219
  • 16
  • 28
11

Addressing the question of presenting the push notifications permissions dialog again as needed for testing -- this is certainly a workaround, but here goes:

Having just finished work on an app that uses Push Notifications extensively, and having tried all the usual permutations, without success ... I ultimately realized that the most streamlined way to work around that issue was to get a device to use only for testing (i.e., a low-end iPod Touch).

To reset the dialog, do a Settings > General > Reset > Erase All Content and Settings. Go thru the device's setup process, reinstall the app and Go.

This was the only way I found to test the 'first launch' experience on demand, as needed during the course of development/testing. It also added a lot of additional versatility to the process.

Shouldn't have needed to resort to all this, but I'm very glad I did, as it turned out to be a real godsend. FWIW.

[P.S. It will probably also prove handy in the future for testing beta versions of the OS, etc.]

rondoagogo
  • 664
  • 6
  • 22
  • 2
    There's a better way to do this - https://developer.apple.com/library/ios/technotes/tn2265/_index.html Scroll to the bottom of that Tech Note ("Resetting the Push Notifications Permissions Alert on iOS") to see instructions for resetting the push notification permissions without resetting the device. This is useful if you can't use a dedicated dev device, and don't want to have to reset your personal device every time. – Sid Mar 03 '14 at 18:56
  • 1
    This, in combination with @Sid's comment is the correct answer. I followed the process at the link referenced by sid and I was able to repeat the alert showing. Though Erase All Content and Settings is more practical, not everyone will have an iDevice available only for testing. – Chris Apr 24 '14 at 16:33
7

At launch, your app should be requesting a token via:

- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types

and will get a token from iOS in the delegate message:

– application:didRegisterForRemoteNotificationsWithDeviceToken:

iOS will prompt the user to allow notifications only when necessary. If remote notifications are already authorized for your app the alert will not appear and your app will get a valid token.

Net is you can't force the alert but you don't need to.

XJones
  • 21,959
  • 10
  • 67
  • 82
  • will my application always get inside this method – application:didRegisterForRemoteNotificationsWithDeviceToken: at launch time? can't test yet here at home, will check though tomorrow at work – Vincent Bacalso Nov 07 '11 at 12:38
  • 3
    You will always get one of `application:didRegisterForRemoteNotificationsWithDeviceToken:` or `application:didFailToRegisterForRemoteNotificationsWithError:` – XJones Nov 07 '11 at 16:54
  • i see, i got this error, no valid ‘aps-environment, well anyway thanks for the answer :D – Vincent Bacalso Nov 08 '11 at 01:55
  • sure thing. read the docs on APNS. your app isn't provisioned correctly yet. FWIW, not sure what your trying to build but to implement remote notifications in your app you also need a backend service. Apple's docs cover this as well. – XJones Nov 08 '11 at 02:02
  • it's okay already, got multiple profiles, just removed unnecessary profiles and use the profile with push notification, thanks again – Vincent Bacalso Nov 08 '11 at 05:14
  • An accurate and working way answer the question in the title is described here: http://stackoverflow.com/a/4080720/129202 (Works for iOS7/8) – Jonny Mar 17 '15 at 06:05
  • perhaps but the real question here was how to get a new token. so whether iOS prompts the user to allow notifications wasn't really relevant. However, the answer you link to is a good one. – XJones Mar 17 '15 at 21:55
3

Temporarily change your package id.

com.mycompany.app - > com.mycompany.app1

Tom
  • 1,610
  • 1
  • 15
  • 19
  • I found this as the easier way to test your app over and over again rather then turning your device on-off and setting different date. – fahrulazmi Mar 22 '15 at 20:58
3

Yes.

http://developer.apple.com/library/ios/#technotes/tn2265/_index.html

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.

perezda
  • 496
  • 4
  • 11
  • Apparently this is broken and a bug report has been opened with Apple. – perezda Jul 12 '12 at 18:28
  • 1
    Apple say this only works with iOS < 5 (i.e. <= 4.*) It's not clear if they mean the clock setting trick only works with iOS < 5, or uninstalling for a day only works with iOS < 5. – rjmunro May 14 '13 at 12:40