【问题标题】:CLLocation stops in IOSCLLocation 在 IOS 中停止
【发布时间】:2016-11-11 11:39:33
【问题描述】:

我正在尝试使用 iOS 和 swift 发送我的位置,但过了一会儿,应用程序停止并停止工作。

    class Location:NSObject, CLLocationManagerDelegate {

private var locationManager = CLLocationManager()
private var errorLocation: Bool = false
private var stuffLocation: CLLocation!

var outSocket: OutSocket!
var timer: NSTimer!
var stuff: Stuff!

override init() {
    super.init()
    outSocket = OutSocket()
    setupLocation()
}

func setupLocation() {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestWhenInUseAuthorization()
    locationManager.activityType = CLActivityType.Fitness
    locationManager.allowsBackgroundLocationUpdates = true
    locationManager.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if !errorLocation {
        errorLocation = true
        locationManager.allowDeferredLocationUpdatesUntilTraveled(10, timeout: 50)
        stuffLocation = locations[0]
        if timer == nil {
            timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: #selector(Location.sendDataToServer), userInfo: nil, repeats: true)
        }
    }
}
}
func locationManager(manager: CLLocationManager, didFinishDeferredUpdatesWithError error: NSError?) {
    errorLocation = false
}

这是我的代码,如果有人做过类似的事情或知道如何防止APP停止,将不胜感激。

【问题讨论】:

  • 应用程序停止接收 GPS 信息,因为每个事件都会更新 GPS 控制数据,以便将 TCP 套接字连接到我的服务器。我读到iOS会停止后台应用程序,但对此了解不多。
  • 当我离开应用程序本身时应用程序停止。例如,当我访问 Facebook 或只是在锁定设备时。
  • 关闭所需的时间约为 3 到 5 小时。有时mejos一个小时。但是,如果我将 dispositovo 连接到 Mac,则不会发生这种情况。
  • 没有互联网(或)数据是不可能的。如果应用程序处于暂停状态,则在我们尝试更新位置时每 500 m 半径坐标发生变化。但不准确的位置得到。用于实现“startSignificantMethod”
  • 您知道导致某种形式的 cachar 错误吗?

标签: ios swift background cllocationmanager


【解决方案1】:

如果您希望您的应用在后台继续获取 GPS 位置更新,您必须在应用的 info.plist 中的 UIBackgroundModes 数组中添加一个条目,然后您需要征求用户的许可。在UIBackgroundModes 上的 Xcode 文档中进行搜索。具体看location的值。

您还需要向 Apple 证明,当您将应用提交到应用商店时,应允许您的应用在后台使用 GPS。

请注意,如果您始终保持 GPS 开启和 TCP 套接字以上传坐标,您将很快耗尽用户的电池。

【讨论】:

  • 允许您提及并被添加到上述应用程序中,但由于某种原因继续被逮捕。
猜你喜欢
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-17
  • 2017-02-20
相关资源
最近更新 更多