0

I have been using https://github.com/Jawbone/UPPlatform_iOS_SDK for a while now and getting the user's daily steps.

I wanted to pull data from the Jawbone API when the app is in background state. I have followed this tutorial : http://www.devfright.com/ios-7-background-app-refresh-tutorial/ To call this method :

[UPMoveAPI getMovesWithLimit:10U completion:^(NSArray *moves, UPURLResponse *response, NSError *error) {
    NSLog(@"This is not getting executed in background");
}];

The jawbone session is successfully verified and seems that my session is active. But I get no response and the above NSLog doesn't get executed in background. Please I have tried contacting Jawbone support, seems that they are not replying back.

Anyone experienced the same, please help.

Omkar Jadhav
  • 1,046
  • 3
  • 16
  • 41

1 Answers1

0

Try below code options:

Option-1

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
   [UPMoveAPI getMovesWithLimit:10U completion:^(NSArray *moves, UPURLResponse *response, NSError *error) {
       NSLog(@"This is not getting executed in background");
   }];
}

Option-2 https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

bgTask = [application beginBackgroundTaskWithName:@"MyTask" expirationHandler:^{
        // Clean up any unfinished task business by marking where you
        // stopped or ending the task outright.
        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    }];

    // Start the long-running task and return immediately.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        // Do the work associated with the task, preferably in chunks.

        [application endBackgroundTask:bgTask];
        bgTask = UIBackgroundTaskInvalid;
    });

Also note that you require to add UIBackgroundModes in info.plist

Hope this helps.

Mrunal
  • 13,982
  • 6
  • 52
  • 96