2011-08-18 10 views
0

배경에 데이터를 게시하려고하는데 CLLocation Manager를 사용하려고 일정한 간격으로 응답을 보내고 싶습니다. 그러나 didUpdateToLocation 메서드는 한 번만 호출합니다. 제발 나에게 제안 해주세요! 여기에 코드위치 배경 - 네트워크 연결

- (void)applicationDidEnterBackgroundUIApplication *)application 
    { 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m 
    [locationManager startUpdatingLocation]; 
    UIApplication* app = [UIApplication sharedApplication]; 

    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ 
    [app 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 
    // code for Posting Data Here 
    NSLog(@"backgroundTimeRemaining: %f", [[UIApplication sharedApplication] backgroundTimeRemaining]); 
    [app endBackgroundTask:bgTask]; 
    bgTask = UIBackgroundTaskInvalid; 
    }); 

    } 
    - (void)locationManagerCLLocationManager *)manager 

didUpdateToLocationCLLocation *)를 newLocation fromLocationCLLocation *)를 입력 oldLocation {

NSLog ("위치 변경") @; } 이 메서드는 한 번만 호출합니다.

답변

0

물론, 위임자가받은 메시지가 적어도 한 번 이상 행복해야합니다. 백그라운드 실행 코드에 응용 프로그램이 일시 중지되는 코드는 없습니다. 또한이 종류의 코드는 약 10 분 동안 작동 할 수 있으며 시스템에 의해 종료됩니다.

당신은 아마 당신은 그냥 의 Info.plist에서 응용 프로그램의 백그라운드 작업이 모드를 설정보다, 배경에서 사용자 위치를 추적 (UIBackgroundModes 및 옵션을 위치 추가)과 앱이 중단되지 않습니다해야하는 경우 (메모리 사용량이 많은 경우에만)