iOS 8推送註冊方式改變的問題

來源:互聯網
上載者:User

標籤: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推送註冊方式改變的問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.