且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查IOS 8中是否启用了本地通知

更新时间:2022-06-05 01:48:55

你可以使用 UIApplication检查它 currentUserNotificationSettings

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]){ // Check it's iOS 8 and above
    UIUserNotificationSettings *grantedSettings = [[UIApplication sharedApplication] currentUserNotificationSettings];

    if (grantedSettings.types == UIUserNotificationTypeNone) {
        NSLog(@"No permiossion granted");
    }
    else if (grantedSettings.types & UIUserNotificationTypeSound & UIUserNotificationTypeAlert ){
        NSLog(@"Sound and alert permissions ");
    }
    else if (grantedSettings.types  & UIUserNotificationTypeAlert){
        NSLog(@"Alert Permission Granted");
    }
}

希望这有帮助,如果您需要更多,请告诉我信息

Hope this helps , Let me know if you need more info