watchOS2 - CMSensorRecorder

时间:2015-07-02 12:35:41

标签: javascript core-motion watch-os-2

我想使用Apple Watch的历史加速度计数据,我的accDataList总是为零。我在类的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 Extension [2158:2428612]开始录制

2015-07-11 22:02:55.279 emmoveDataWatchOS Extension [2158:2428612] AW:开始动作更新

2015-07-11 22:02:55.279 emmoveDataWatchOS Extension [2158:2428612] AW EMWatchManager:startMovementDetection

2015-07-11 22:02:55.279 emmoveDataWatchOS Extension [2158:2428612]可选(CMSensorRecorder:0x797733d0)

2015-07-11 22:10:51.483 emmoveDataWatchOS Extension [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 Extension [2158:2428612]可选(CMSensorRecorder:0x797733d0)

2015-07-11 22:10:51.486 emmoveDataWatchOS Extension [2158:2428612] AccDataList:nil

4 个答案:

答案 0 :(得分:0)

也许你可以尝试

func startMovementDetection(){
    self.startDate = NSDate()
    self.cmSensorRecorder?.recordAccelerometerFor(self.recorderDuration)
}

并查看Swift watchOS 2 - CMSensorDataList

答案 1 :(得分:0)

CMSensorRecorder也有一个错误:你应该等待3到5分钟才能重启你的录音机,否则列表将总是返回nil。(你可以观看Apple的视频了解更多细节。)

答案 2 :(得分:0)

我遇到了同样的问题,在这篇文章中找到了解决方案:

https://forums.developer.apple.com/thread/15470

"在开始重新录制时,显然不喜欢将充电器插入手表"

只需将设备与充电器断开即可。有道理,但当然没有在任何地方正式记录......

答案 3 :(得分:0)

确保已启用“设置”>“隐私”>“运动和健身”>“健身跟踪”。

如果禁用,CMSensorRecorder.accelerometerData()似乎总是返回nil,即使

CMSensorRecorder.isAccelerometerRecordingAvailable() == true

CMSensorRecorder.authorizationStatus() == .authorized