Capture answer to “App would like to send you push

2019-03-29 21:09发布

问题:

The first time you call registerForRemoteNotificationTypes: on your UIApplication object, a UIAlertView pops up saying "[app] would like to send you push notifications".

Is there any way to know when "OK" or "Don't allow" is tapped in this AlertView?

Currently application:didRegisterForRemoteNotificationsWithDeviceToken: is called on my AppDelegate, even before a user makes a decision.

The reason I ask is because on first launch, I want to push a ViewController with Notification options, but only if the user indicated that they want to receive notifications.

回答1:

You can use next method of UIApplication:

Returns the types of notifications the application accepts.

- (UIRemoteNotificationType)enabledRemoteNotificationTypes

For example,

UIRemoteNotificationType status = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (status == UIRemoteNotificationTypeNone)
{
     NSLog(@"user is not subscribed to receive push notifications");
}