"업데이트 됨. 그러나 이로 인해 배터리가 더 많이 소모됩니다."
그건 사실이 아닙니다. didUpdateLocation을 사용하여 필요한 정밀도 수준을 조정할 수 있습니다. 당신이 원하는 정도에 따라, 장치는 대신 기본 GPS 수신기의 휴대 전화 위치 데이터를 사용하는 모든 시간에 예를 돌렸다 :
배터리 소모 500 미터의 정밀도 낮은를
CLLocationAccuracy의 myaccuracy = 500.00;
최대의 정확성과 당신이 가질 수있는 최대 배터리 배수 (충전기에 연결되는 장치가 필요합니다)
CLLocationAccuracy myaccuracy = -1.0;
당신이 어떤 값에 대해 선택해야합니다하지 않은 경우 또한 상수를 사용할 수 있습니다 :
통근 const를 CLLocationAccuracy kCLLocationAccuracyBestForNavigation을; < - 의미 -1.0
extern const CLLocationAccuracy kCLLocationAccuracyBest;
extern const CLLocationAccuracy kCLLocationAccuracyNearestTenMeters;
extern const CLLocationAccuracy kCLLocationAccuracyHundredMeters;
extern const CLLocationAccuracy kCLLocationAccuracyKilometer;
extern const CLLocationAccuracy kCLLocationAccuracyThreeKilometers;
https://developer.apple.com/library/mac/#documentation/CoreLocation/Reference/CoreLocationConstantsRef/Reference/reference.html#//apple_ref/c/data/kCLLocationAccuracyBest
지금 당신의 질문에 대답 :
didUpdateLocation에만 작동 당신이 startUpdatingLocation로을 locationManager를 요청할 때.
startMonitoringSignificantLocationChanges를 사용하면 GPS 장치에서 정보를 얻지 못합니다. 이 방법을 사용하면 휴대 전화가 셀 타워에서 다른 셀 타워로 변경되면 앱이 깨어납니다 (예 : 기차 또는 자동차로 여행 중). 앱이 그것에 의해 깨울 때, 당신은 구현해야합니다
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue) {
NSLog(@"locationValue received, now needs to start updateLocation again");
//your code goes here
}
내부에
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
}
그런 다음 didUpdateLocation 알림을 수신하기 위해 다시 일반 startUpdatingLocation을 시작할 수 있습니다.또는 Apple 설명서를 확인하고 launchOptions에 앱 시작시 위치 정보가 있는지 확인할 수 있습니다.
작성한 코드를 입력하십시오. – Durgaprasad
self.locationManager = [[CLLocationManager alloc] init]; _locationManager.delegate = self; _locationManager.pausesLocationUpdatesAutomatically = NO; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; [_locationManager startUpdatingLocation]; – Maddy
백그라운드 방법 [_locationManager startMonitoringSignificantLocationChanges] – Maddy