我按照所有步骤设置了$?
,但我怀疑在AppDelegate中编写函数xterm
时犯了一个错误。
以下是我模拟background fetch
performFetchWithCompletionHandler
这是我的代码:
background fetch
如何测试Warning: Application delegate received call to - application:
performFetchWithCompletionHandler:but the completion handler was never called.
是否有效?
答案 0 :(得分:3)
如果未输入第一个if语句,则永远不会调用完成处理程序。此外,当您循环浏览视图控制器时,您可能找不到正在查找的视图控制器,这意味着永远不会调用完成。最后,在调用完成处理程序之后,您应该放置一个return
。
func application(
application: UIApplication,
performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
guard let tabBarController = window?.rootViewController as? UITabBarController,
let viewControllers = tabBarController.viewControllers else {
completionHandler(.failed)
return
}
guard let notificationsViewController = viewControllers.first(where: { $0 is NotificationsViewController }) as? NotificationsViewController else {
completionHandler(.failed)
return
}
notificationViewController.reloadData()
completionHandler(.newData)
}