gpt4 book ai didi

ios - 在指定时间间隔使用 CoreLocation 在后台检索 CoreMotion 数据

转载 作者:行者123 更新时间:2023-11-28 08:09:11 24 4
gpt4 key购买 nike

我有一个汽车应用程序需要在指定的时间间隔(0.5 秒)在前台和后台跟踪 CoreMotion 和 CoreLocation 数据。用户控制跟踪的开始和停止,因此我们不必担心电池生命周期问题。这是我目前拥有的:

var locationManager:CLLocationManager?
var motionManager:CMMotionManager?

override init() {
super.init()
locationManager = CLLocationManager()
motionManager = CMMotionManager()
locationManager?.delegate = self
locationManager?.allowsBackgroundLocationUpdates = true
}

//Call this to start tracking
func startTracking() {
motionManager?.startDeviceMotionUpdates()
locationManager?.startUpdatingLocation()
}
//Call this to stop tracking
func stopTracking(){
locationManager?.stopUpdatingLocation()
motionManager?.stopDeviceMotionUpdates()
}

//Using CoreLocation delegate method to retrieve both motion and location data.
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last{
if let data = motionManager?.deviceMotion {
print("Data: \(data) Location:\(location)")
}
}
}

我现在遇到的这个问题是我无法控制为了获取我的 CoreMotion 数据而进行位置更新的频率。我需要在后台每 0.5 秒跟踪一次 CoreMotion 数据,CoreLocation 数据不必频繁。有更好的方法吗?

最佳答案

很抱歉回复晚了,但要设置更新间隔,您应该写:

motionManager.deviceMotionUpdateInterval = 0.5

关于ios - 在指定时间间隔使用 CoreLocation 在后台检索 CoreMotion 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com