Objective-C获取应用是否允许消息通知的方法

来源:互联网 发布:阿里云 运营商 编辑:程序博客网 时间:2024/06/05 13:29

用户可能对应用设置是否允许通知,OC的API中iOS8之前和之后是两个方法:

- (BOOL)isAllowedNotification {

    if ([[UIDevice currentDevice].systemVersion doubleValue] < 8.0) {
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if(UIRemoteNotificationTypeNone != type)
        return YES;
    }else{
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types) {
            return YES;
        }
    }
    return NO;
}

0 0
原创粉丝点击