【问题标题】:Continuous location details when app is killed/Terminated应用程序被杀死/终止时的连续位置详细信息
【发布时间】:2017-07-13 22:39:29
【问题描述】:

当应用程序被杀死/终止时如何获取连续的位置详细信息? 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];
}

【问题讨论】:

  • 如果您使用持续位置更新,您的应用将在应用商店中被拒绝
  • @Anbu :我有理由这样做我的应用程序有点像超级汽车跟踪。需要不断更新位置吗?

标签: ios objective-c core-location


【解决方案1】:

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

【讨论】:

  • 这个方法不起作用。如果您的应用程序不在前台,操作系统最终永远不会交付它们。也许你会得到第一个……但第二个……第三个……第四个……永远不会到来。
  • 是的,你是对的,当应用程序被杀死时它不起作用
猜你喜欢
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多