2017-01-21 13 views
1

위치 추적 애플리케이션을 개발 중입니다. 사용자는 추적을 시작하고, 원하는대로 (배경에 앱 놓기, 전화 잠금 등), 앱으로 돌아가서 추적을 중지 할 수 있습니다.iOS CoreLocation in background

시스템 또는 사용자가 앱을 종료하면 추적을 다시 시작하고 싶습니다. 그렇게하기 위해 중요한 위치 변경 서비스를 사용해야한다는 의사를 확인했지만이 서비스는 충분한 위치를 전송하지 않습니다. 중요한 위치 변경 서비스 덕분에 앱이 다시 시작될 때 표준 위치 서비스를 다시 시작할 수 있습니까? 아니면 앱이 거부됩니까? 백그라운드에서 사망하는 경우

답변

0

다음 방법은 당신의 응용 프로그램을 깨울 것 :

  1. 지역 이벤트
  2. 방문 이벤트
  3. 중요한 위치 이벤트 귀하의 응용 프로그램과 함께 시작됩니다

위치 키는 applicationDidFinishLaunchingWithOptions 방법입니다. 다음 (http://nshipster.com/launch-options/에서) 정상적으로를 처리하는 방법에 대한 예는 다음과 같습니다 또한

// .h 
@import CoreLocation; 

@interface AppDelegate() <CLLocationManagerDelegate> 
@property (readwrite, nonatomic, strong) CLLocationManager *locationManager; 
@end 

// .m 
- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // ... 

    if (![CLLocationManager locationServicesEnabled]) { 
     [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Location Services Disabled", nil) 
            message:NSLocalizedString(@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled.", nil) 
            delegate:nil 
          cancelButtonTitle:NSLocalizedString(@"OK", nil) 
          otherButtonTitles:nil] show]; 
    } else { 
     self.locationManager = [[CLLocationManager alloc] init]; 
     self.locationManager.delegate = self; 
     [self.locationManager startMonitoringSignificantLocationChanges]; 
    } 

    if (launchOptions[UIApplicationLaunchOptionsLocationKey]) { 
     [self.locationManager startUpdatingLocation]; 
    } 
} 

, 당신은 당신이 다른 사용 사례에 대해 서로 다른 메커니즘을 사용할 수있는 등 중요한 위치 모니터링 또는 지역 모니터링을 사용하도록 제한되지 않습니다. 예 : 지역 모니터링을 사용하여 사용자 주변의 대체 지역을 설정하고 이탈 이벤트가 발생할 때마다 애플리케이션이 location 키를 사용하여 깨어납니다. 그런 다음 위치 서비스를 다시 시작할 수 있습니다.