我正在开发一个应用程序。我正在更新用户的后台位置。我想在特定时间间隔内更新该位置。我已经搜索了很多。但没有得到任何解决方案。请帮帮我。下面是我的代码。提前致谢。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
{
let userLocation :CLLocation = locations[0] as CLLocation
print("user latitude = \(userLocation.coordinate.latitude)")
print("user longitude = \(userLocation.coordinate.longitude)")
self.labelLat.text = "\(userLocation.coordinate.latitude)"
self.labelLongi.text = "\(userLocation.coordinate.longitude)"
DataBaseFunctions.sharedInstance.saveUserDetail(dataToInsert: userLocation)
}
最佳答案
这是在 Swift-NOW 中, 您可以将 Timer 用于 didUpdateLocation 和
locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
locationManager.delegate = self
locationManager.startUpdatingLocation()
var timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateLocation), userInfo: nil, repeats: true)
func updateLocation() {
let location: CLLocation = locationManager.location
// Your code
}
//标记:- CLLocationManagerDelegate
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
// Your code
}
关于ios - 如何使用 swift 4 iOS 在特定时间间隔内更新用户的后台位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51785053/