iOS 8.0后,获取推送通知类型改了,iOS 8.0的推送通知类型 是 UIUserNotificationType ,iOS 7.0 的推送通知类型 是UIRemoteNotificationType,所以需要先判断iPhone的系统版本,大于等于8.0以上的通过
//获取通知中心 是否 允许程序通知消息的值,7.0的用
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
// 获取通知中心 是否 允许程序通知消息的值。
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
推送通知类型有:
UIUserNotificationTypeNone = 0, // the application may not present any UI upon a notification being received
UIUserNotificationTypeBadge = 1 << 0, // the application may badge its icon upon a notification being received 中文解释就是 App右上角标推送通知消息的数量
UIUserNotificationTypeSound = 1 << 1, // the application may play a sound upon a notification being received 中文解释就是 App推送通知时的声音设置
UIUserNotificationTypeAlert = 1 << 2, // the application may display an alert upon a notification being received 中文解释就是 App推送通知时的警报设置
如果通知中心不允许推送的话,types的值肯定为0,所以对应推送类型为UIUserNotificationTypeNone,贴出判断中心是否允许程序推送通知的代码
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0f) {
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone == setting.types) {
NSLog(@"推送关闭 8.0");
}
else
{
NSLog(@"推送打开 8.0");
}
}
else
{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if(UIRemoteNotificationTypeNone == type){
NSLog(@"推送关闭");
}
else
{
NSLog(@"推送打开");
}
}