IOS Firebase background fetch

非 Y 不嫁゛ 提交于 2019-12-06 11:38:49

When using application(_:didReceiveRemoteNotification:) you must always call the completion handler, no matter what. Apples policy is that you call completionHandler(.newData) if your fetch found new data, completionHandler(.noData) if your fetch didn't find any new data, and completionHandler(.failed) if your fetch found new data, but failed while trying to retrieve it.

In your code the completion handler is only called if certain conditions are met. Instead of not calling the completion handler, you should call completionHandler(.failed) or completionHandler(.noData).

Thus, your final code (updated for Swift 3) will be:

func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    var newData = false
    if let tabBarController = window?.rootViewController as? UITabBarController,
        viewControllers = tabBarController.viewControllers! as [UIViewController]!
    {
        for viewController in viewControllers {
            if let a1 = viewController as? HorariosViewController {
                newData = true
                a1.interface()   
            }
        }
    }
    completionHandler(newData ? .newData : .failed) // OR completionHandler(newData ? .newData : .noData)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!