2012-03-23 4 views
1

내 서비스에는 GPS가 필요합니다. 실제로 GPS를 켜고 위치가 유효한지 확인한 다음 잠시 동안 잠자기 상태로 들어가는 서비스를 구현했습니다. (5 초에서 시작하여 움직임이 감지되지 않으면 최대 1 분 동안 잠을 잘 수 있습니다.) 그 후 다시 GPS를 시작하고 새 위치를 얻습니다.iOS GPS 배터리 방전, 어떻게 배터리를 덜 소모 시키나요?

하지만 배터리 소모가 여전히 높습니다! 필자는 locMgr.distanceFilter = 10.0f 및 desiredAccurady = NearestTenMeters를 사용했습니다.

어떻게하면 배터리 소모를 최소화 할 수 있습니까?

답변

1

내가 처리하는 방법입니다. 위치를 잡은 후에 NSDictionary에 저장합니다. 그런 다음 다시 위치를 지정해야하는 경우 GPS를 다시 켜는 대신 NSDictionary를 반환합니다. 2 분 후에 NSDictionary를 리셋합니다 (가장 좋은 스위트 룸이있는 시간을 조정할 수 있습니다). NSDictionary가 리셋 된 후 다음에 위치가 필요하면 GPS에서 새 위치를 가져옵니다.

- (NSDictionary *) getCurrentLocation { 

if (self.currentLocationDict == nil) { 
    self.currentLocationDict = [[NSMutableDictionary alloc] init]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    [locationManager startUpdatingLocation]; 

    CLLocation *myLocation = [locationManager location]; 

    [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.latitude] forKey:@"lat"]; 
    [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.longitude] forKey:@"lng"]; 
    [locationManager stopUpdatingLocation]; 
    [locationManager release]; 

    //Below timer is to help save battery by only getting new location only after 2 min has passed from the last time a new position was taken. Last location is saved in currentLocationDict 
    [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(resetCurrentLocation) userInfo:nil repeats:NO]; 
} 

return self.currentLocationDict; 
} 

- (void) resetCurrentLocation { 
NSLog(@"reset"); 
[currentLocationDict release]; 
self.currentLocationDict = nil; 
} 
+0

이것은 내가 원하는 것만은 아닙니다. 배터리 소모에 대해 더 많은 통찰력이 필요합니다. –

관련 문제