通知开启状态判断

来源:互联网 发布:linux telnet连不上 编辑:程序博客网 时间:2024/05/10 21:06



/**
 *  判断是否开启通知
 */
- (BOOL)isAllowedNotification {
    //iOS8 check if user allow notification
    if ([self isSystemVersioniOS8]) {// system is iOS8
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types) {
            return YES;
        }
    } else {//iOS7
        UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
        if(UIRemoteNotificationTypeNone != type)
        return YES;
    }
    
    return NO;
}

- (BOOL)isSystemVersioniOS8 {
    //check systemVerson of device
    UIDevice *device = [UIDevice currentDevice];
    float sysVersion = [device.systemVersion floatValue];
    
    if (sysVersion >= 8.0f) {
        return YES;
    }
    return NO;
}

0 0
原创粉丝点击