Hello!
I’m having trouble using background fetch on swift 2.0 according to the tutorial → https://www.raywenderlich.com/92428/background-modes-ios-swift-tutorial.
I get this error:
application:performFetchWithCompletionHandler: but the completion handler was never called.
Basically i have a function that where i perform my actions (calling data on firebase) and i want it to execute on background.
here is my app delegate code :
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()
}
}
}
}
and this is how i get data from firebase :
func interface(){
DataService.dataService.REF_BASE.observeEventType(.Value, withBlock: { snapshot in
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)
}
}
}
})
Thanks in advance.