- (void)registerForRemoteNotificationTypes:(UIRemoteNotificationType)types NS_DEPRECATED_IOS(3_0, 8_0, "Please use registerForRemoteNotifications and registerUserNotificationSettings: instead")php
昨天晚上整理PUSH的東西,準備些一個教程,所有弄好以後,發現沒有達到預期的效果,本覺得是服務器代碼的問題(由於本人對PHP代碼一點都不懂),因此在網上四處搜索,後來看xcode log才發現,原來是IOS8系統更新了的問題,提示 registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later. 使用IOS8 xcode6的同窗,在使用推送(push)的時候應該已經出現這個問題了。那麼讓咱們來看看具體的解決方法。 iOS 8 has changed notification registration in a non-backwards compatible way. While you need to support iOS 7 and 8 (and while apps built with the 8 SDK aren't accepted), you can check for the selectors you need and conditionally call them correctly for the running version. Here's a category on UIApplication that will hide this logic behind a clean interface for you that will work in both Xcode 5 and Xcode 6. // IOS8 新系統須要使用新的代碼咯 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { //這裏仍是原來的代碼 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; } 本來在IOS7當中 判斷PUSH是否打開的方法是: UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; return (types & UIRemoteNotificationTypeAlert); 若是將這段代碼使用在 IOS當中,雖然不會出現crash的現象,可是基本沒什麼做用。 在IOS8中,咱們使用以下的新代碼來取代以上的代碼 { UIRemoteNotificationType types; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { types = [[UIApplication sharedApplication] currentUserNotificationSettings].types; } else { types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; } return (types & UIRemoteNotificationTypeAlert); } 每當蘋果更新一個新的版本的時候,最痛苦的莫過於咱們這羣屌絲啊 加油碼農! 本文轉自 http://www.999dh.net/home.php?mod=space&uid=1&do=blog&quickforward=1&id=419 轉載請註明!!