標籤:style blog http io os 使用 ar for 檔案
不久之後iPhone 6/6 plus就會在國內如雨後春筍般遍地開花了。iOS 8早已現行一步,不過有的開發人員也注意到了在iOS 8上推播通知的註冊方式有所變化,報錯提示為
| 1 |
registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later. |
之後國外有開發人員在使用了新的解決方案註冊成功後發現在iPhone 6上仍然不能運行。鑒於iPhone 6/6 Plus將在國內開售,我們大可未雨綢繆一下。
iOS 8因為改變了推送訊息的註冊方式,所以在有推送需求的應用開發時,需要有些與以前不同的修改。然後可以試試在appDelegate.m檔案的didFinishLaunchingWithOptions方法中加入下面一段代碼以避免在iPhone 6/6 Plus上出現問題:
| 123456789101112 |
#ifdef __IPHONE_8_0 //這裡主要是針對iOS 8.0,相應的8.1,8.2等版本各程式員可自行發揮,如果蘋果以後推出更高版本還不會使用這個註冊方式就不得而知了……if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings];} else { UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];}#elseUIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];#endif |
然後在appDelegate.m中加入此方法:
| 123456 |
#ifdef __IPHONE_8_0- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings{ [application registerForRemoteNotifications];}#endif |
iOS 8推送註冊方式改變的問題