3

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

leppie
  • 115,091
  • 17
  • 196
  • 297
Narsail
  • 735
  • 1
  • 8
  • 12

4 Answers4

0

Maybe you can try to

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

And have a look at Swift watchOS 2 - CMSensorDataList

Community
  • 1
  • 1
0

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

Cassie Xia
  • 45
  • 8
0

I had the same problem, found the solution in this 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"

Just need to disconnect the device from its charger. Makes sense, but of course not documented officially anywhere...

Tamir
  • 625
  • 1
  • 12
  • 27
0

Make sure that Settings > Privacy > Motion & Fitness > Fitness Tracking is enabled.

If it's disabled, CMSensorRecorder.accelerometerData() always seems to return nil even though

CMSensorRecorder.isAccelerometerRecordingAvailable() == true

and

CMSensorRecorder.authorizationStatus() == .authorized

quark
  • 1,725
  • 1
  • 14
  • 23