【发布时间】:2016-04-13 08:00:52
【问题描述】:
根据教程,我在 swift 2.0 上使用后台获取时遇到问题 -> https://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial3。 我收到此错误: 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: 的调用,但从未调用过完成处理程序。
提前致谢。
【问题讨论】:
-
请显示您的代码...以及来自 XCode 的确切错误/警告消息...
-
@kishan94 我刚刚编辑了我的问题。
-
我认为completionHandler调用应该是completionHandler(UIBackgroundFetchResult.NewData)
-
您的代码中似乎没有 Firebase 观察或查询功能,因此不清楚快照的来源。将异步代码作为后台进程运行可能会导致其他问题,但这取决于用例是什么。
标签: ios swift firebase background-fetch