web-dev-qa-db-ja.com

registerForRemoteNotificationTypesの場合のiOS用のビルド:iOS 8.0以降ではサポートされていません

デバイスが通知を登録する方法に重大な変更があり、registerForRemoteNotificationTypesを使用できない場合、Xcode 6ベータを使用できない場合、iOS 8をサポートするアプリの新しいバージョンをどのように構築できますか?ユーザーがプッシュ通知を引き続き取得できるように、Xcode 6 GMバージョンがリリースされた日にビルドして送信する必要がありますか?

18
Jason Hocker

iOS 8は通知登録を変更しました。したがって、デバイスのバージョンを確認してから、通知設定を登録する必要があります。( this リンクを確認してください。)私はXcode 6でこのコードを試してみました。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        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;
}
50
Raşit ERASLAN

システムのバージョンをチェックするのではなく、respondsToSelectorを使用することを検討してください。

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]){
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
17
alex da franca
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
#else
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
#endif
11
Muhammad Adil

AppleドキュメントregisterForRemoteNotificationTypes:はiOS 8では廃止予定です。代わりにregisterForRemoteNotificationsregisterUserNotificationSettings:を使用できます。

Xcode 6ベータ版およびiOS 8ベータ版はプレリリース版のソフトウォーです。ベータ版は開発とテストのみを目的としています。 App Storeに送信するには、XcodeとiOSのリリースバージョンで新しいアプリとアプリのアップデートをビルドする必要があります。

3
VoidStack
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)];
}
3
Hardik Bar

あなたはこれを使うことができます、

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
    {
        // for iOS 8
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [application registerForRemoteNotifications];
    }
    else
    {
        // for iOS < 8
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }

    // RESET THE BADGE COUNT 
    application.applicationIconBadgeNumber = 0;
1
Neenu

このコードをAppDelegate didFinishLaunchingWithOptions関数で記述します

 if([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotifications)]) {
UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
 }
        else {
UIRemoteNotificationType types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:types];
  }    [self.window makeKeyAndVisible];
return YES;
0
amit gupta