应用程序被终止或终止时的连续位置详细信息

时间:2017-02-23 12:34:50

标签: ios objective-c core-location

如何在应用被杀/终止时获取连续的位置详细信息? startMonitoringSignificantLocationChanges方法在500米后触发didUpdateLocations委托方法。但我希望每10米在杀戮模式下进行位置更新。或者我想在后台自动重新启动应用程序并在后台启动位置更新。目前我在后台有工作代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    if ([launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey]) {
        [[LocationManager sharedLocarionManager] updateAccuracy:YES];
        [[LocationManager sharedLocarionManager].locationManager requestAlwaysAuthorization];
        [[LocationManager sharedLocarionManager].locationManager stopUpdatingLocation];
        [[LocationManager sharedLocarionManager].locationManager startUpdatingLocation];
        [[LocationManager sharedLocarionManager].locationManager stopMonitoringSignificantLocationChanges];
        [[LocationManager sharedLocarionManager].locationManager startMonitoringSignificantLocationChanges];

    }
    return YES;
}

LocationManager.m

- (id)init {
    self = [super init];
    if(self != nil) {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        self.locationManager.distanceFilter = 100; // meters
        self.locationManager.delegate = self;
    }

    return self;
}

-(void)updateAccuracy:(BOOL)trackingAccuracy {

    if (trackingAccuracy) {
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        self.locationManager.distanceFilter =  10.0 ; // meters
        self.locationManager.allowsBackgroundLocationUpdates = YES;
    } else {
        self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
        self.locationManager.distanceFilter = 100; // meters
    }

    [ self.locationManager startUpdatingLocation];
    [self.locationManager startMonitoringSignificantLocationChanges];
}

1 个答案:

答案 0 :(得分:0)

有一个解决方法。虽然您的应用程序被杀死时无法获得连续位置,但您可以通过服务器向用户发送静默推送通知以获取有关其位置的更新。当应用程序收到静音推送通知时,您将获得30秒的窗口。在那么短的时间内,你必须执行你的任务。