javascriptcore-motionwatchos-2

watchOS2 - CMSensorRecorder


I want to use the historical accelerometer data from the Apple Watch and my accDataList is always nil. I instantiated CMSensorRecorder in the init function of the class. Does someone 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()
    }        
}

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) to 2015-07-11 20:10:51 +0000

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

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


Solution

  • Maybe you can try to

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

    And have a look at Swift watchOS 2 - CMSensorDataList