(iOS8中 用户开启的推送通知类型 对应的是 UIUserNotificationType (下边代码中 UIUserNotificationSettings 的types属性的类型) ,iOS7对应的是UIRemoteNotificationType)
那么如何获得呢,在iOS8中是通过types属性,[[UIApplication sharedApplication] currentUserNotificationSettings].types
如果用户没有允许推送,types的值必定为0
1 /**
2 * check if user allow local notification of system setting
3 *
4 * @return YES-allowed,otherwise,NO.
5 */
6 + (BOOL)isAllowedNotification { 7 //iOS8 check if user allow notification 8 if ([UIDevice isSystemVersioniOS8]) {// system is iOS8 9 UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings]; 10 if (UIUserNotificationTypeNone != setting.types) { 11 return YES; 12 } 13 } else {//iOS7 14 UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 15 if(UIRemoteNotificationTypeNone != type) 16 return YES; 17 } 18 19 return NO; 20 }
下面这个方法我是添加在UIDecive的Category中的,用于判断当前系统版本是大于iOS8还是小于iOS8的
1 /**
2 * check if the system version is iOS8
3 *
4 * @return YES-is iOS8,otherwise,below iOS8
5 */
6 + (BOOL)isSystemVersioniOS8 { 7 //check systemVerson of device 8 UIDevice *device = [UIDevice currentDevice]; 9 float sysVersion = [device.systemVersion floatValue]; 10 11 if (sysVersion >= 8.0f) { 12 return YES; 13 } 14 return NO; 15 }