Push Notifications Permissions

2019-03-27 15:19发布

问题:

Trying to work around a few corner cases for when push notifications are denied in the app and I have two questions:

1) Is there a way to reset whether the user has seen the notification request pop up?

2) Is there any way to determine if the user has said no to the notification request?

回答1:

1) No, unless there's some private API that does that, but that's not allowed by Apple

2) The first time your app is started, after calling registerForRemoteNotificationTypes, you can check if didRegisterForRemoteNotificationsWithDeviceToken is called. If it's not, the user said "No thanks".



回答2:

You can always check the status of the permissions if the user changes them, you can check them on applicationDidBecomeActive

- (void)applicationDidBecomeActive:(UIApplication *)application
{
     if ([[UIApplication sharedApplication]  respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
        if ([[UIApplication sharedApplication]  isRegisteredForRemoteNotifications]){
            NSLog(@"Notifications Enabled ios 8");
        } else {
            NSLog(@"Notifications not Enabled ios 8");
        }
    } else {
        UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if (types & UIRemoteNotificationTypeAlert)
        {
            NSLog(@"Notifications Enabled");
        }
        else
        {
            NSLog(@"Notifications not Enabled");
        }
    }

}

updated to make it work on iOS 8 too