HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 我收到一个警告,说我在模拟后台提取时从未调用完成处理程序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我按照所有步骤设置了后台提取,但我怀疑在AppDelegate中编写函数performFetchWithCompletionHandler时我犯了一个错误.

这是我模拟后台提取时得到的警告

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-fetchis是否正常工作?

解决方法

如果未输入第一个if语句,则永远不会调用完成处理程序.此外,当您循环浏览视图控制器时,您可能找不到正在查找的视图控制器,这意味着永远不会调用完成.最后,您应该在调用完成处理程序后返回一个返回值.

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)
}

大佬总结

以上是大佬教程为你收集整理的ios – 我收到一个警告,说我在模拟后台提取时从未调用完成处理程序全部内容,希望文章能够帮你解决ios – 我收到一个警告,说我在模拟后台提取时从未调用完成处理程序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。