2017-01-21 6 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キーで起動します。その後、ロケーションサービスを再開できます。