iOS8 检查远程通知类型的权限 [英] iOS8 check permission of remotenotificationtype

查看:26
本文介绍了iOS8 检查远程通知类型的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以像这样检查用户是否在 iOS8 之前授予通知(警报)权限:

I can check if user granted notification (alert) permission or not before iOS8 like that:

UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (types & UIRemoteNotificationTypeAlert)
{
    //user granted
}

它不适用于 iOS8,它说:

it is not working on iOS8, it says:

iOS (3.0 and later) Deprecated:Register for user notification settings using the  registerUserNotificationSettings: method instead.

控制台说:

enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.

那么我如何在 iOS 8 上检查它?

so how can I check it on iOS 8?

推荐答案

好的,我的问题是这样解决的:

Ok I solved my problem like this:

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

这篇关于iOS8 检查远程通知类型的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆