iOS9中註冊遠程通知的方法

來源:互聯網
上載者:User

iOS9中註冊遠程通知的方法

在以往的版本中,我們可以通過:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:some types]

來註冊遠程通知,不過很快該方法就被標記為廢棄,並且提示我們要用另一個類似的方法:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound categories:nil];    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

別高興的太早,雖然registerUserNotificationSettings方法現在照樣工作,不過其中的諸如UIRemoteNotificationTypeXXX之類的類型很快又被標記為廢棄…

好吧,在iOS9中,註冊遠程通知變成了如下類似的代碼:

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeSound|UIUserNotificationTypeBadge|UIUserNotificationTypeAlert categories:nil];        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];        [[UIApplication sharedApplication] registerForRemoteNotifications];

額,你沒看錯,以上代碼在註冊遠程通知的同時還註冊了本地通知,所以我們可以理解為遠程通知只是在原有本地通知基礎上開啟了遠程功能.不過這隻是我個人的理解,歡迎錯誤修正. ;)

  

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.