【发布时间】: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