關於remote-notification

  • 問題:在啓動程序時,日誌裏面打印了:You've implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.

這句話的意思是咱們在UIApplicationDelegate中實現了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但沒有在Info.plist中的UIBackgroundModes添加remote-notification。以前作這個推送的同事說這個提示沒有關係,一直都有這句提示的,並且咱們的推送功能一直是正常的。可是我內心仍是有些疑問,那就問問度娘吧。html

 

解決方案:技術分享網絡

技術分享

 

原文:http://www.cnblogs.com/yonggezai/p/4826713.htmlapp

 

極光推送官網給出的解答是less

這句話主要是提示開發者若是要支持UIBackgroundModes,須要開啓Remote notifications,具體操做能夠看:iOS 7 Background Remote Notification測試

看了半天,仍是沒有理解Remote notifications有什麼特色,後來在知乎上看到了一個問題「爲何iOS僞後臺,可是有不少軟件也會在後臺一直運行?」,有一個答案對remote notificaions解釋的很清楚:fetch

推送喚醒(remote notifications)iOS7之前,當你收到推送消息時,你須要先打開應用,等待應用從網絡上獲取推送的信息以後,才能將信息呈現出來。而iOS7改變了這一過程。當系統收到推送消息時,不是首先提醒用戶,而是喚醒對應的應用,讓應用在後臺獲取對應的信息。當信息處理完成後,再提醒用戶。一個很小的改變,可是能夠很大的提高用戶體驗。一樣,iOS系統也會限制這種推送消息的頻率,防止系統被頻繁喚醒影響續航。
——來自知乎網友Jeffrey Linthis

這個時候再結合那兩張 Apple 官方對IOS6和iOS7對比的圖片,就很容易理解了。spa


Remote Notifications in iOS6.jpg

Remote Notifications in iOS7 .png

UIApplicationDelegate中提供了兩個方法來處理推送的回調,其中第二個方法是iOS7之後纔有的:日誌

// 若是app在前臺運行,系統收到推送時會調用該方法 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { } // 無論app是在前臺運行仍是在後臺運行,系統收到推送時都會調用該方法 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler { /* Use this method to process incoming remote notifications for your app. * Unlike the application:didReceiveRemoteNotification: method, * which is called only when your app is running in the foreground, * the system calls this method when your app is running in the foreground or background. }

這兩個方法長得很像,可是職責不一樣,。code

如今的問題是:
1.咱們實現了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但沒有設置UIBackgroundModes的remote-notification,有什麼影響嗎?
2.既然有了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,爲何還要application:didReceiveRemoteNotification: 呢?

 

我測試了一下兩個遺留問題:
1.咱們實現了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,但沒有設置UIBackgroundModes的remote-notification,有什麼影響嗎?
不設置UIBackgroundModes的remote-notification的話,除了推送喚醒功能不生效以外,沒發現有其餘影響。

2.既然有了application:didReceiveRemoteNotification:fetchCompletionHandler:方法,爲何還要application:didReceiveRemoteNotification: 呢?
我看了API文檔,是這麼說的:
Implement the "application:didReceiveRemoteNotification:fetchCompletionHandler:" method instead of this one(application:didReceiveRemoteNotification:) whenever possible. 
If your delegate implements both methods, the app object calls the "application:didReceiveRemoteNotification:fetchCompletionHandler:" method.
因此application:didReceiveRemoteNotification:方法應該是沒用了。

轉自  祥龍Shannon

原文:http://www.jianshu.com/p/9a25418ab84e

相關文章
相關標籤/搜索