watchOS2 - CMSensorRecorder
watchOS2 - CMSensorRecorder
我想使用 Apple Watch 的加速度计历史数据,但我的 accDataList 始终为零。我在class的init函数中实例化了CMSensorRecorder。有人以前遇到过这个问题吗?
func startMovementDetection(){
self.cmSensorRecorder?.recordAccelerometerFor(self.recorderDuration)
self.startDate = NSDate()
}
func extractHistoricalAccelerometerData(){
var accDataList = self.cmSensorRecorder!.accelerometerDataFrom(self.startDate, to: NSDate())
NSLog("AccDataList : \(accDataList)")
if accDataList != nil {
accDataList = accDataList as CMSensorDataList
for accData in accDataList {
self.addHistoricalAccDataToMovementArray((accData as? CMRecordedAccelerometerData)?.acceleration)
}
self.sendDataToIphone()
}
}
日志如下所示:
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] 开始录制
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] AW:开始运动更新
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] AW EMWatchManager: startMovementDetection
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] 可选(CMSensorRecorder: 0x797733d0)
2015-07-11 22:10:51.483 emmoveDataWatchOS 扩展[2158:2428612] AW:定格动画更新
2015-07-11 22:10:51.484 emmoveDataWatchOS Extension[2158:2428612] 从 Optional(2015-07-11 20:02:55 +0000) 提取数据到 2015-07-11 20:10:51 +0000
2015-07-11 22:10:51.484 emmoveDataWatchOS 扩展[2158:2428612] 可选(CMSensorRecorder: 0x797733d0)
2015-07-11 22:10:51.486 emmoveDataWatchOS 扩展[2158:2428612] AccDataList:无
也许你可以试试
func startMovementDetection(){
self.startDate = NSDate()
self.cmSensorRecorder?.recordAccelerometerFor(self.recorderDuration)
}
然后看看
CMSensorRecorder 也有一个错误:您应该等待 3 到 5 分钟才能重新启动 Recorder,否则列表将始终 return nil。(您可以观看 Apple 的视频了解更多详细信息。)
我遇到了同样的问题,在这个 post:
中找到了解决方案
https://forums.developer.apple.com/thread/15470
"It apparently does not like the charger to be plugged in on the watch when starting recroding"
只需断开设备与充电器的连接。有道理,但当然没有正式记录在任何地方...
确保已启用“设置”>“隐私”>“运动与健身”>“健身追踪”。
如果它被禁用,CMSensorRecorder.accelerometerData()
似乎总是 return 零,即使
CMSensorRecorder.isAccelerometerRecordingAvailable() == true
和
CMSensorRecorder.authorizationStatus() == .authorized
我想使用 Apple Watch 的加速度计历史数据,但我的 accDataList 始终为零。我在class的init函数中实例化了CMSensorRecorder。有人以前遇到过这个问题吗?
func startMovementDetection(){
self.cmSensorRecorder?.recordAccelerometerFor(self.recorderDuration)
self.startDate = NSDate()
}
func extractHistoricalAccelerometerData(){
var accDataList = self.cmSensorRecorder!.accelerometerDataFrom(self.startDate, to: NSDate())
NSLog("AccDataList : \(accDataList)")
if accDataList != nil {
accDataList = accDataList as CMSensorDataList
for accData in accDataList {
self.addHistoricalAccDataToMovementArray((accData as? CMRecordedAccelerometerData)?.acceleration)
}
self.sendDataToIphone()
}
}
日志如下所示:
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] 开始录制
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] AW:开始运动更新
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] AW EMWatchManager: startMovementDetection
2015-07-11 22:02:55.279 emmoveDataWatchOS 扩展[2158:2428612] 可选(CMSensorRecorder: 0x797733d0)
2015-07-11 22:10:51.483 emmoveDataWatchOS 扩展[2158:2428612] AW:定格动画更新
2015-07-11 22:10:51.484 emmoveDataWatchOS Extension[2158:2428612] 从 Optional(2015-07-11 20:02:55 +0000) 提取数据到 2015-07-11 20:10:51 +0000
2015-07-11 22:10:51.484 emmoveDataWatchOS 扩展[2158:2428612] 可选(CMSensorRecorder: 0x797733d0)
2015-07-11 22:10:51.486 emmoveDataWatchOS 扩展[2158:2428612] AccDataList:无
也许你可以试试
func startMovementDetection(){
self.startDate = NSDate()
self.cmSensorRecorder?.recordAccelerometerFor(self.recorderDuration)
}
然后看看
CMSensorRecorder 也有一个错误:您应该等待 3 到 5 分钟才能重新启动 Recorder,否则列表将始终 return nil。(您可以观看 Apple 的视频了解更多详细信息。)
我遇到了同样的问题,在这个 post:
中找到了解决方案https://forums.developer.apple.com/thread/15470
"It apparently does not like the charger to be plugged in on the watch when starting recroding"
只需断开设备与充电器的连接。有道理,但当然没有正式记录在任何地方...
确保已启用“设置”>“隐私”>“运动与健身”>“健身追踪”。
如果它被禁用,CMSensorRecorder.accelerometerData()
似乎总是 return 零,即使
CMSensorRecorder.isAccelerometerRecordingAvailable() == true
和
CMSensorRecorder.authorizationStatus() == .authorized