iOSでプッシュ通知を実装する方法の超詳細まとめ

  • 投稿日:
  • by
  • カテゴリ:
Lancorkさんから。http://www.lancork.net

追記(2014/11/04)
registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later.

iOS8よりregisterForRemoteNotificationTypesが使えなくなった。
ターゲットがiOS7でも動作しないため、iOSのバージョンを判定した上で対応する必要あり。

    /* iOS8より、registerForRemoteNotificationTypesは、使えない。

    [[UIApplication sharedApplication]registerForRemoteNotificationTypes:

     (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

     return YES;

    */

    

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

    {

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    }

    else

    {

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:

         (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];

    }

    return YES;