2015/02/20

[iOS][Objective-C]iOS8のpush notificationの仕様変更について

iOS8でデバッグしていると以下のようなエラーメッセージが表示された。

registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.
そこで、qiitaのiOS8のRemote Notificationの登録メソッドについてを読みながら修正を加えてみた。

ちなみにiOS7以前までは、
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
としていた。

今回、iOS8では下のように変更した。
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
確かに動いたけど、なんか釈然としないなー。

0 コメント:

コメントを投稿