iOS8可以接收推送通知但不支持iOS7

问题描述:

/*--- Setup Push Notification ---*/ 
    //For iOS 8 
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)] && [UIApplication instancesRespondToSelector:@selector(registerForRemoteNotifications)]) 
    { 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
    } 
    //For iOS 7 & less 
    else if ([UIApplication instancesRespondToSelector:@selector(registerForRemoteNotificationTypes:)]) 
    { 
     UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; 
    } 

嗨!我希望有人能帮助我。我已经更新了我的代码,以获得针对iOS8的推送通知。在iOS8设备上一切正常,但似乎推送通知不再适用于iOS7设备。有什么我失踪?感谢您的帮助!iOS8可以接收推送通知但不支持iOS7

使用此代码

if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil]]; 
    } else { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound]; 
    } 

     #ifdef __IPHONE_8_0 
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { 
    [application registerForRemoteNotifications]; 
} 
#endif 

与其他推相关方法。这将在内部监督办公室工作..

希望这会帮助你。

+0

谢谢!让我尝试。 – 2014-12-12 03:47:58