问题描述
我正在为watchOS开发一个滑翔伞应用程序,它可以显示和记录诸如海拔,速度,滑行率等值。
到目前为止,我已经构建了UI,集成了一些设置,并且正在接收压力传感器数据和gps位置。 为了节省电池寿命,我添加了一个“停止按钮”,用于触发locationManager.stopUpdatingLocation和CMAltimeter.stopRelativeAltitudeUpdates函数。但是在控制台中,我可以看到静止的位置和海拔高度的更新。
我将代码上传到https://github.com/LukeCrouch/iAlti/tree/main/iAlti%20WatchKit%20Extension。 有趣的文件可能是ControlsView,在这里我声明并调用相关函数。
func stopLocation() {
self.locationManager.stopUpdatingLocation()
}
我非常感谢我能获得的所有帮助,这是我第一次编写App! :)
欢呼卢克
解决方法
问题是这一行:
import numpy as np
import matplotlib.pyplot as plt
#xs = np.linspace(1,21,200)
plt.figure(figsize=(6,3))
plt.hlines(y='Test1',xmin=1929,xmax=1978,colors='red',linestyles='-',lw=2,label='Test1')
plt.hlines(y='Test2',xmin=1800,xmax=1991,colors='blue',label='Test2')
plt.hlines(y='Test3',xmin=1930,xmax=2007,colors='green',label='Test3')
plt.show()
每次重新生成ControlsView时,该行都会重新运行。因此,LocationManager是一个不同的LocationManager。因此,您要告诉一个LocationManager的CLLocationManager停止更新,但这与开始的CLLocationManager是一个不同的。
相反,将其设置为一个单例环境对象,以便您的应用仅具有 one 个LocationManager和一个 one CLLocationManager。这样,每次与之交谈时,您都在同一个交谈。