가장 큰 부분은이 질문에 대한 다른 대답으로 동료 @csexton이 기술 한 기술입니다.
전환 후 10 초의 거리 시간 만 가져 오는 두 번째 문제를 해결하기 위해 추가 시간을 요청할 수 있습니다. iOS를 사용하면 백그라운드에서 최대 180 초 동안 계속해서 작업 할 수 있습니다. 배경 모드가 필요없고 AppStore의 특별한 허가가 필요하지 않습니다. 여기
는 당신이 것을 설정하는 방법은 다음과 같습니다
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
if (_inBackground) {
[self extendBackgroundRunningTime];
}
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self logString: [NSString stringWithFormat:@"applicationDidEnterBackground"]];
[self extendBackgroundRunningTime];
_inBackground = YES;
}
- (void)extendBackgroundRunningTime {
if (_backgroundTask != UIBackgroundTaskInvalid) {
// if we are in here, that means the background task is already running.
// don't restart it.
return;
}
NSLog(@"Attempting to extend background running time");
__block Boolean self_terminate = YES;
_backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithName:@"DummyTask" expirationHandler:^{
NSLog(@"Background task expired by iOS");
if (self_terminate) {
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTask];
_backgroundTask = UIBackgroundTaskInvalid;
}
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"Background task started");
while (true) {
NSLog(@"background time remaining: %8.2f", [UIApplication sharedApplication].backgroundTimeRemaining);
[NSThread sleepForTimeInterval:1];
}
});
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
[self logString: [NSString stringWithFormat:@"applicationDidBecomeActive"]];
_inBackground = NO;
}
에는 은색 총알이 백그라운드에서 범위를 180 초입니다 얻기 없지만, 10 초하지 않는 것을 많은 사용 사례를 해결합니다.
현재 테스트 결과와 함께, 이것이 어떻게 작동하는지에 대한 전체 작성자를 읽을 수 있습니다
https://github.com/RadiusNetworks/ibeacon-background-demo/tree/background-task이 질문을 해결할 수있는 답이있다? 또는 그것을 해결할 수 있습니까? – aeren