iOS 8.0后拢蛋,獲取推送通知類型改了,iOS 8.0的推送通知類型 是 UIUserNotificationType 长已,iOS 7.0 的推送通知類型 是UIRemoteNotificationType旋恼,所以需要先判斷iPhone的系統(tǒng)版本,大于等于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右上角標推送通知消息的數(shù)量
UIUserNotificationTypeSound = 1 << 1, // the application may play a sound upon a notification being received 中文解釋就是 App推送通知時的聲音設(shè)置
UIUserNotificationTypeAlert = 1 << 2, // the application may display an alert upon a notification being received 中文解釋就是 App推送通知時的警報設(shè)置
如果通知中心不允許推送的話,types的值肯定為0贱勃,所以對應(yīng)推送類型為UIUserNotificationTypeNone井赌,貼出判斷中心是否允許程序推送通知的代碼
if ([[UIDevice currentDevice].systemVersion floatValue]>=8.0f) {
UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
if (UIUserNotificationTypeNone == setting.types) {
NSLog(@"推送關(guān)閉 8.0");
}
else
{
NSLog(@"推送打開 8.0");
}
}
else
{
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if(UIRemoteNotificationTypeNone == type){
NSLog(@"推送關(guān)閉");
}
else
{
NSLog(@"推送打開");
}
}