我一直在使用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支持,似乎他们没有回复。
任何有相同经验的人,请帮忙。
答案 0 :(得分: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");
}];
}
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
希望这有帮助。