2014-11-05 23 views
1
if([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 

     [self registerForiOS8PushSettings]; //for iOS8 

    } else { 
//iOS7 or earlier 

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 

    } 

無法將推送通知發送到iOS7設備。 didRegisterForRemoteNotificatiosnWithDeviceToken被調用,實際上消息已成功發送。在iOS8中運行良好。iOS推送通知在iOS 8上工作,但不在iOS SDK 8.1中的iOS 7上

+0

可能重複[iOS 8的功能的設備沒有收到推送通知後,代碼更新](http://stackoverflow.com/questions/25909568/ IOS -8-啓用-設備未接收推通知 - 後 - 編碼 - 更新) – CRDave 2014-11-05 11:08:06

回答

1

隨着iOS8的過程發生了變化。爲了讓您的應用程序註冊iOS8上和早期版本使這樣的事情:

-(void)registerAppForNotifications{ 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
    { 
     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 
    else 
    { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 
    } 

}