2014-12-11 106 views
-1
/*--- 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

回答

1

使用此代碼

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