我已经使用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");
}];jawbone会话已成功验证,并且我的会话似乎处于活动状态。但是我没有得到响应,上面的NSLog也不会在后台执行。我已经联系过Jawbone支持,他们似乎没有回复。
任何有同样经历的人,请帮助。
发布于 2015-02-19 18:40:51
尝试下面的代码选项:
选项-1\f25-1\f6
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
希望这能有所帮助。
https://stackoverflow.com/questions/28432030
复制相似问题