Push Notifications Permissions

不打扰是莪最后的温柔 提交于 2019-12-03 13:28:04

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

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

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