根据教程-> https://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial3 ,我在 swift 2.0 上使用后台获取时遇到问题。我收到此错误: application:performFetchWithCompletionHandler: 但从未调用过完成处理程序。
基本上我有一个功能,我可以在其中执行我的操作(在 firebase 上调用数据),我希望它在后台执行。
这是我的应用委托代码
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(
UIApplicationBackgroundFetchIntervalMinimum)
}
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 a1 = viewController as? HorariosViewController {
completionHandler(.NewData)
a1.interface()
}
}
}
}
这是我在接口函数上从firebase获取数据的方式:
func interface() {
self.numeroDasOrações = []
self.adhan = []
if let snapshots = snapshot.children.allObjects as? [FDataSnapshot] {
for snap in snapshots {
if let postDictionary = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let hSalat = Horarios(key: key, dictionary: postDictionary)
let hAdhan = Horarios(key: key, dictionary: postDictionary)
self.numeroDasOrações.append(hSalat)
self.adhan.append(hAdhan)
}
}
}
})
}
Xcode 错误:
警告:应用程序委托收到了对 -application:performFetchWithCompletionHandler: 的调用,但从未调用过完成处理程序。
提前致谢。