How to show "Would like to send you Push Notifications" Alert View again?

21,504

Solution 1

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.

Solution 2

  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

Solution 3

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

Solution 4

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.

Solution 5

Temporarily change your package id.

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

Share:
21,504
Vincent Bacalso
Author by

Vincent Bacalso

Experienced iOS Developer with a demonstrated history of working in the information technology and services industry. Vincent Bacalso approaches work in the IT with a sense of quality like an artist. Strives to create more efficient workflows and a documentation nerd. Web Developer at Arcanys (2018-Present) Independent Contractor at TrustArc/CMIL (2018) iOS Developer at TrigID (2018) iOS Developer at Factnexus (2017-2018) Independent iOS Developer iOS Developer at Arcanys (2016-2017) iOS Apps Analyst at Truste now TrustArc (2015-2016) iOS Developer at OveractiveInk Cebu (2013-2016) Mobile Developer at NextIX Cebu, Philippines (2011-2013)

Updated on March 20, 2020

Comments

  • Vincent Bacalso
    Vincent Bacalso over 4 years

    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
    Vincent Bacalso over 12 years
    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
  • XJones
    XJones over 12 years
    You will always get one of application:didRegisterForRemoteNotificationsWithDeviceToken‌​: or application:didFailToRegisterForRemoteNotificationsWithError‌​:
  • Vincent Bacalso
    Vincent Bacalso over 12 years
    i see, i got this error, no valid ‘aps-environment, well anyway thanks for the answer :D
  • XJones
    XJones over 12 years
    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.
  • Vincent Bacalso
    Vincent Bacalso over 12 years
    it's okay already, got multiple profiles, just removed unnecessary profiles and use the profile with push notification, thanks again
  • perezda
    perezda almost 12 years
    Apparently this is broken and a bug report has been opened with Apple.
  • rjmunro
    rjmunro about 11 years
    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.
  • Sid
    Sid over 10 years
    There's a better way to do this - 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.
  • Chris
    Chris about 10 years
    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.
  • Jonny
    Jonny over 9 years
    An accurate and working way answer the question in the title is described here: stackoverflow.com/a/4080720/129202 (Works for iOS7/8)
  • XJones
    XJones over 9 years
    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.
  • fahrulazmi
    fahrulazmi over 9 years
    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.