美文网首页
推送权限

推送权限

作者: 执拗的男孩 | 来源:发表于2020-04-01 11:22 被阅读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
    

    相关文章

      网友评论

          本文标题:推送权限

          本文链接:https://www.haomeiwen.com/subject/ttuouhtx.html