【问题标题】:Rejected due to background location mode由于后台定位模式而被拒绝
【发布时间】:2014-07-16 01:38:15
【问题描述】:

由于以下原因,我的应用更新 (1.1) 被拒绝: We found that your app uses a background mode but does not include functionality that requires that mode to run persistently.

但我的应用仍然使用 1.0 版中的相同功能。

我做什么: 在位置更新时,我检查新位置是否在特定区域(矩形)内:

- (BOOL)locationInRegion: (CLLocation *) lastLocation {
    if ((lastLocation.coordinate.latitude < self.overlayTopLeftCoordinate.latitude && lastLocation.coordinate.latitude > self.overlayBottomLeftCoordinate.latitude) &&
        (lastLocation.coordinate.longitude < self.overlayTopRightCoordinate.longitude && lastLocation.coordinate.longitude > self.overlayTopLeftCoordinate.longitude)) {
        return YES;
    }
    return NO;
}

在前台和后台模式下,如果用户在这个区域,我会在 MKMapView 上绘制一个碎屑路径。如果没有,我什么都不做。

需要后台模式 -> 用于位置更新的应用注册在我的 .plist 中

我做错了什么?

我的描述中没有此信息:

继续使用在后台运行的 GPS 可以显着提高 减少电池寿命。

这可能是(唯一的)原因吗?

【问题讨论】:

  • 在后台绘制信息?这似乎不是很有用...
  • 该应用显示带有自定义主题公园覆盖的地图视图。并在位置更新时在地图上绘制一条碎屑路径,用户可以看到他已经访问过哪个景点..

标签: ios objective-c location core-location cllocationmanager


【解决方案1】:

您的应用被拒绝有两种可能的原因。

它是:-

a) 您的应用在后台时不需要位置更新。

b) 您的应用无法正确处理后台位置更新

如果是后者,您需要在后台处理位置更新以及后台任务。你需要这样的东西

- (id)init {
   if (self==[super init]) {
    //Get the share model and also initialize myLocationArray
    self.shareModel = [LocationShareModel sharedModel];
    self.shareModel.myLocationArray = [[NSMutableArray alloc]init];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
 }
 return self;
}

-(void)applicationEnterBackground{
  CLLocationManager *locationManager = [LocationTracker sharedLocationManager];
  locationManager.delegate = self;
  locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
  locationManager.distanceFilter = kCLDistanceFilterNone;
  [locationManager startUpdatingLocation];

  //Use the BackgroundTaskManager to manage all the background Task
  self.shareModel.bgTask = [BackgroundTaskManager sharedBackgroundTaskManager];
  [self.shareModel.bgTask beginNewBackgroundTask];
}

以上只是完整解决方案的一个sn-p。我已经分享了一个上传到 Github 的完整解决方案,以及一篇关于如何在 iOS 7 后台持续获取位置更新的博文:Background Location Services not working in iOS 7

【讨论】:

  • 你好,我需要任何额外的编码工作来在后台更新用户位置吗?到目前为止,将app registers for location updates 添加到.plist 就足够了。如果我在 plist 中删除它,我不会在后台获得任何更新。
  • 是的,如果您需要后台位置更新,那么您将需要额外的代码。我在 Github 上已经有了完整的解决方案,可以为你节省大量的实验时间。也访问我的博客。很多cmet和不同开发者发来的问题。
  • 我已经调试到- (void)locationManager:(CLLocationManager*)manager didUpdateLocations:(NSArray *)locations,如果应用程序处于后台模式,我会得到更新。如果我从 plist 中删除后台模式,我不会得到任何更新。那么为什么我需要额外的代码呢?
  • 关键字是persistently。尝试运行您当前的应用程序并让它运行 1 小时以上。由于它已被 Apply 拒绝,我 99% 确定您的应用将从 background mode 移动到 suspended mode,然后它将不再获取位置更新,直到您再次点击应用程序以将其移至活动模式。去阅读我的博客并从 Github 下载解决方案以了解所有内容。
  • 谢谢,那是我不明白的缺失信息
【解决方案2】:

是的,如果您未能在应用说明中添加以下警告文本并且您已启用后台定位模式,Apple 将拒绝您的应用。

Continued use of GPS running in the background can dramatically decrease battery life.

【讨论】:

    猜你喜欢
    • 2013-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    • 2021-08-01
    • 1970-01-01
    • 2012-07-31
    相关资源
    最近更新 更多