【问题标题】:ios app background runios应用后台运行
【发布时间】:2017-01-06 12:31:44
【问题描述】:

像“blitzer.de”enter image description here 这样的应用程序怎么可能在后台连续运行? enter image description here 我正在尝试创建一个这样的应用程序,并让它在使用 gps 数据的同时在后台运行大约 2 小时。 我的研究告诉我,苹果对后台运行非常严格,将在 3 分钟内取消该进程。提取也将在 6 分钟内结束。任何帮助将不胜感激。

【问题讨论】:

标签: ios background


【解决方案1】:

@约翰内斯

1) 任何应用都可以在后台运行不超过 10 分钟。但这里是 Background Enabled App 的例外情况。所以你必须从

启用后台模式

功能 > 后台模式

2) 现在您必须在应用程序的 info.plist 中请求位置跟踪的权限——始终

NSLocationAlwaysUsageDescription --- 我需要位置

NSLocationWhenInUseUsageDescription --- 我需要位置

隐私 - 位置使用说明 --- 我需要位置

3) 现在最重要。守则

  self.locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
    [self.locationManager requestAlwaysAuthorization];
    self.locationManager.delegate = self;
    if([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
        [self.locationManager setAllowsBackgroundLocationUpdates: YES];
    }
    self.locationManager.distanceFilter = 50 ; // 
    self.locationManager.activityType=CLActivityTypeAutomotiveNavigation;
    [self.locationManager startUpdatingLocation];
    [self.locationManager setPausesLocationUpdatesAutomatically:NO];

4)。 setPausesLocationUpdatesAutomatically:NO 会让你的应用持续运行。

【讨论】:

  • 从 iOS 9 开始,10 分钟改为 3 分钟。
  • 最后(非编码,也许是最难的)步骤是将您的应用程序作为导航应用程序提交给 Apple,并让他们同意批准。如果你不是一个普通的导航应用程序,那就很难卖了。
  • @rocoenes 如果您始终要求位置权限,您将获得比您想象的更多的背景时间。
猜你喜欢
  • 2012-01-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-27
  • 2015-04-25
相关资源
最近更新 更多