iOS8から、enabledRemoteNotificationTypesがサポートされなくなりました。(enabledRemoteNotificationTypes is not supported in iOS 8.0 and later.)
そのため、iOS8の場合は分岐させ、通知登録がされているかどうかを確認する必要がある。
【詳細手順】
- (BOOL)isEnabledToNotify
{
if ( [[UIDevice currentDevice].systemVersion floatValue] >= 8.0){
// iOS8以上の場合に実行.
// 通知していいかのアラートを表示.
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
return [[UIApplication sharedApplication] isRegisteredForRemoteNotifications];
}
else{
// 今まで通り実行.
UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (type == UIRemoteNotificationTypeNone) {
return NO;
}
}
return YES;
}
また、iOS8から、設定画面で通知登録の変更する場所が変わってます。
「設定」 > 「アプリ名」 > 「通知」画面の「通知を許可」でオン・オフ
【参照】
registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later | stackoverflow
iOS8 check permission of remotenotificationtype | stackoverflow