LocationManager连接到计算机时在后台发送,但断开连接后停止发送..?

时间:2016-01-29 02:18:53

标签: ios swift location

我可以让位置管理员在后台正确更新位置,但只有在手机连接到我的macbook时才能更新]:

在pList中,我有 NSLocationAlwaysUsageDescription 值以及 应用程序寄存器进行位置更新所需的背景模式 应用程序从网络下载内容

在AppDelegate中我懒得加载locationManager,然后在viewcontroller初始化之后,我调用 locationManager.startUpdatingLocation()

lazy var locationManager:CLLocationManager! = {
        let manager = CLLocationManager()
        manager.desiredAccuracy = kCLLocationAccuracyBest
        manager.delegate = self
        manager.allowsBackgroundLocationUpdates = true
        manager.requestAlwaysAuthorization()
        return manager
    }()



    func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
        // Add another annotation to the map.
        let annotation = MKPointAnnotation()
        annotation.coordinate = newLocation.coordinate


        var latitude:String = annotation.coordinate.latitude.description
        var longitude:String = annotation.coordinate.longitude.description


        print("new location...\(latitude) - \(longitude)")
    }

我做错了什么?

0 个答案:

没有答案