推送权限
2020-04-01 本文已影响0人
执拗的男孩
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
if (settings.authorizationStatus == UNAuthorizationStatusAuthorized) {
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusSuccess);
}
}
else {
if (@available(iOS 12.0, *)) {
if(settings.authorizationStatus == UNAuthorizationStatusProvisional)
{
NSLog(@"临时的");
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusSuccess);
}
}
}
else {
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusFailure);
}
}
}
}];
#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
UIUserNotificationSettings *settings = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (settings.types == UIUserNotificationTypeNone) {
NSLog(@"禁止");
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusFailure);
}
}
else {
NSLog(@"允许");
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusSuccess);
}
}
#else
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (type == UIRemoteNotificationTypeNone) {
NSLog(@"禁止");
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusFailure);
}
}
else {
NSLog(@"允许");
if (returnBlock) {
returnBlock(BestWebMessageCallbackResultStatusSuccess);
}
}
#endif