WatchOS2 - CMSensorRecorder

I want to use the historical accelerometer data from Apple Watch and my accDataList is always zero. I created an instance of CMSensorRecorder in the init function of the class. Has anyone had this problem before?

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()
    }        
}

      

The log looks like this:

2015-07-11 22: 02: 55.279 emmoveDataWatchOS Extension [2158: 2428612] Start recording

2015-07-11 22: 02: 55.279 emmoveDataWatchOS Extension [2158: 2428612] AW: Start motion updates

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] Optional (CMSensorRecorder: 0x797733d0)

2015-07-11 22: 10: 51.483 emmoveDataWatchOS Extension [2158: 2428612] AW: Stop motion updates

2015-07-11 22: 10: 51.484 emmoveDataWatchOS Extension [2158: 2428612] Extract data from optional (2015-07-11 20:02:55 +0000) at 2015-07-11 20:10:51 +0000

2015-07-11 22: 10: 51.484 Extension emmoveDataWatchOS [2158: 2428612] Optional (CMSensorRecorder: 0x797733d0)

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

+3


source to share


3 answers


Maybe you can try

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

      



And have a look at Swift watchOS 2 - CMSensorDataList

0


source


CMSensorRecorder also has a bug: you have to wait 3 to 5 minutes to restart the Recorder, otherwise the List will always return zero (you can watch Apple's video for more details.)



0


source


I had the same problem, found the solution in this post:

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

"It looks like he doesn't like having the charger plugged into the watch at startup."

Just disconnect your device from the charger. Makes sense, but of course not officially registered anywhere ...

0


source







All Articles