gpt4 book ai didi

iOS8检查remotenotificationtype的权限

转载 作者:可可西里 更新时间:2023-11-01 05:01:39 26 4
gpt4 key购买 nike

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

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

它不适用于 iOS8,它说:

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 上检查它呢?

最佳答案

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

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检查remotenotificationtype的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25570015/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com