我在iPhone上运行以下代码,但是对于我一生来说,在Apple Watch上运行时似乎看不到任何数据。有什么建议吗?
// works on phone, not on watch
// get pressure readings and sace for later display
if CMAltimeter.isRelativeAltitudeAvailable() {
altimeter.startRelativeAltitudeUpdates(to: OperationQueue.main) { (data, error) in
self.myAltitudePressureMetric = String.init(format: "%.1fM", (data?.relativeAltitude.floatValue)!)
self.myAltitudePressureFeet = String.init(format: "%.1fft", (data?.relativeAltitude.floatValue)! * 3.6)
self.myPressurehPa = String.init(format: "%.2f hPA", (data?.pressure.floatValue)!*10)
}
} else {
myAltitudePressureFeet = " no pressure data"
myAltitudePressureMetric = " no pressure data"
}
答案 0 :(得分:-1)
我不好。
我在里面定义了高度表= CMAltimeter()
唤醒功能(withContext上下文:可以吗?
而不是仅仅在内部
InterfaceController4类:WKInterfaceController
现在可以使用了!感谢您的建议。