woh*_*ras 4 deprecated push-notification apple-push-notifications ios ios8
我可以检查用户是否在iOS8之前授予了通知(警告)权限:
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
//user granted
}
Run Code Online (Sandbox Code Playgroud)
它不适用于iOS8,它说:
iOS (3.0 and later) Deprecated:Register for user notification settings using the registerUserNotificationSettings: method instead.
Run Code Online (Sandbox Code Playgroud)
控制台说:
enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.
Run Code Online (Sandbox Code Playgroud)
那么如何在iOS 8上查看呢?
好的,我这样解决了我的问题:
BOOL isgranted = false;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
isgranted = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
}
#else
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
isgranted = true;
}
#endif
Run Code Online (Sandbox Code Playgroud)