2014-11-05 63 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)]; 
    } 

}