How to show “Would like to send you Push Notificat

2020-02-01 00:34发布

问题:

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.

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



回答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



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



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



回答5:

Temporarily change your package id.

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