您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

推送相關警告怎麼修:Background Modes 忘了開

編輯:iOS 開發綜合

做 iOS 推送時,很可能會看到類似這樣的警告:

**[1412:60b] You've implemented -[<UIApplicationDelegate> application:performFetchWithCompletionHandler:],
but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.

**[1412:60b] 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.

是什麼意思?

訊息講得很直白:你實作了背景抓取與背景接收推送的 delegate 方法,卻沒有在 Info.plist 的 UIBackgroundModes 清單裡申報對應能力。系統於是分からない你到底想做什麼,只能提出警告——而少了這項申報,那些方法基本上不會被呼叫。

解法

路徑是 PROJECT → Capabilities → Background Modes,把 Background fetch 與 Remote notifications 兩項打勾開啟。

另一種常見的警告長這樣:

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.

解法一樣,回到同一個地方勾選即可:

勾選之後 Xcode 會自動幫你把對應的鍵值寫進 Info.plist,不需要手動編輯。順帶一提,開了背景模式之後記得真機測試——模擬器對背景行為的模擬向來不夠準確。

以上就是這個警告的成因與修正方式。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved