3
我遵循所有步驟來設置background fetch
,但我懷疑我寫了函數performFetchWithCompletionHandler
在函數performFetchWithCompletionHandler
AppDelegate中。我得到一個警告,說完成處理程序從來沒有被調用當我模擬後臺提取
這裏只要是我得到的警告,因爲我模仿background fetch
Warning: Application delegate received call to - application:
performFetchWithCompletionHandler:but the completion handler was never called.
這裏是我的代碼:
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
if let tabBarController = window?.rootViewController as? UITabBarController,
viewControllers = tabBarController.viewControllers as [UIViewController]! {
for viewController in viewControllers {
if let notificationViewController = viewController as? NotificationsViewController {
firstViewController.reloadData()
completionHandler(.NewData)
print("background fetch done")
}
}
}
}
如何測試如果background-fetch
工作?
但我的viewController總是在那裏,所以理論上它應該總是找到正確的?它應該總是進入If語句中? – AziCode
我會這麼認爲,但警告似乎證明不是。 – AdamPro13
爲了從'performFetchWithCompletionHandler'中調用位於我的一個VC中的函數,需要通過視圖控制器循環嗎? – AziCode