简体   繁体   English

在不使用位置服务IOS的情况下获取后台位置

[英]Getting Background Location Without using location services IOS

I got my app rejected because 我的应用遭到拒绝,因为

We found that your app uses a background mode but does not include functionality that requires that mode to run persistently. 我们发现您的应用使用后台模式,但不包含要求该模式持续运行的功能。 This behavior is not in compliance with the App Store Review Guidelines. 此行为不符合《 App Store审查指南》。

We noticed your app declares support for location in the UIBackgroundModes key in your Info.plist but does not include features that require persistent location. 我们注意到您的应用在Info.plist的UIBackgroundModes项中声明了对位置的支持,但其中不包含需要永久位置的功能。

I need to track the user location in the background in order to fire a notification if the user is near one of his/her pictures on the application. 我需要在后台跟踪用户位置,以便在用户靠近应用程序上他/她的图片之一时发出通知。 That's why I used background mode key on my .plist 这就是为什么我在.plist上使用背景模式键的原因

This how I initialize my locationManager 这是我如何初始化我的locationManager

_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
_locationManager.distanceFilter = 1000; // Will update evert 1 KM.
_locationManager.activityType = CLActivityTypeFitness;
_locationManager.pausesLocationUpdatesAutomatically = YES;
[_locationManager startUpdatingLocation];

And I'm using didUpdateToLocation to receive the location on the background. 我正在使用didUpdateToLocation来接收背景位置。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    if (_currentLocation == nil){
        self.currentLocation = newLocation;
    }else{

        if([self.currentLocation distanceFromLocation:newLocation]){
            [self getNearPicturesMethod:newLocation];
        }
    }

}

They pointed to me that I should use "startMonitoringSignificantLocationChanges" but still if I remove the background key (what they want) the app won't receive location updates anymore if it's on the foreground, they present only if the user opens it and that doesn't work for me. 他们向我指出,我应该使用“ startMonitoringSignificantLocationChanges”,但如果我删除了背景键(他们想要的),则该应用程序即使在前台也不会再收到位置更新,它们仅在用户打开它时才显示不为我工作。

PS. PS。 I read related questions but nobody seemed to fix this problem or to provide a workaround. 我阅读了相关的问题,但似乎没有人解决此问题或提供解决方法。

Your app will wake on significant location changes. 您的应用会在位置发生重大变化时唤醒。 You do not need the background location mode key set for that. 您不需要为此设置背景位置模式键。 Same goes for region boundary monitoring. 区域边界监视也是如此。

For your case, I think you will more likely want to set regions for the nearest pictures and then just wait for boundaries to be crossed. 对于您的情况,我认为您更可能希望为最近的图片设置区域,然后仅等待越过边界。

Use significant location changes to update the nearest pictures and reset your regions to those. 使用重要的位置更改来更新最近的图片,并将您的地区重置为这些图片。

This will work as intended, be within the guidelines of Apple docs and impact the battery of the user very little, if any. 这将按预期工作,并且符合Apple文档的规定,并且对用户电池的影响很小(如果有的话)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM