Push Notifications Permissions

你说的曾经没有我的故事 提交于 2019-12-12 08:01:41

问题


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



来源:https://stackoverflow.com/questions/3587176/push-notifications-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!