0

我一直在使用https://github.com/Jawbone/UPPlatform_iOS_SDK一段时间,并获取用户的日常步骤。

当应用程序处于后台状态时,我想从 Jawbone API 中提取数据。我遵循了本教程: http: //www.devfright.com/ios-7-background-app-refresh-tutorial/ 调用此方法:

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

颚骨会话已成功验证,似乎我的会话处于活动状态。但我没有得到回应,上面的 NSLog 没有在后台执行。请我尝试联系 Jawbone 支持,他们似乎没有回复。

谁有同样的经历,请帮忙。

4

1 回答 1

0

尝试以下代码选项:

选项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");
   }];
}

选项 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;
    });

另请注意,您需要在 info.plist中添加UIBackgroundModes

希望这可以帮助。

于 2015-02-19T10:40:50.610 回答