Background Fetch


I’m having trouble using background fetch on swift 2.0 according to the 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 {

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 {

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)

Thanks in advance.

Are you running this on the actual device and not the simulator? Are you following the two scenarios described in the “Testing Background Fetch” section? You might need to post some code to figure this out.

I have update my question with the code! I have tried running on simulator as well on a real device. Thanks :wink: