2014-10-10 32 views
0

我正在嘗試爲沒有任何運氣的推送通知註冊Ipad。我已經嘗試了下面的代碼,但在IOS8上獲取錯誤「registerForRemoteNotificationTypes:在iOS 8.0及更高版本中不受支持。」雖然它在IOS7上運行良好。IOS8推送通知

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{ 
    CGRect screenBounds = [[UIScreen mainScreen] bounds]; 


    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
    { 
     NSLog(@"+++++++++++++"); 

     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 
    else 
    { 
     NSLog(@"============"); 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 
    } 

回答

1

更好的方式:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) 
{ 
    // iOS 8 Notifications 
    // use registerUserNotificationSettings 
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
    [[UIApplication sharedApplication] registerForRemoteNotifications]; 
} 
else 
{ 
    // iOS < 8 Notifications 
    // use registerForRemoteNotifications 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert]; 
} 
+0

我曾嘗試提到的代碼現在收到這個錯誤 2014年10月11日13:00:53.555的測試程序[927:173651] enabledRemoteNotificationTypes不支持iOS 8.0及更高版本。 – 2014-10-11 08:01:42