Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading accelerometer data with watchOS2 - iOS9 - XCode 7.0

I'm trying to record and read historical data from the Apple Watch. Unfortunately, associated DataList is always equal to nil.

To be more explicit, on my watch app, I got two buttons: - one to start recording the data - one to read the data

Here is the associated code - running on the WatchKit Extension:

- (IBAction)start {

    // Check authorizations with boolean
    bool toTest_AccelerometerAvailable = [CMSensorRecorder isAccelerometerRecordingAvailable];
    bool toTest_RecordingAuthorized = [CMSensorRecorder isAuthorizedForRecording];

    // Check if recorder has been initialized, then launch record session for 20 seconds
    if ([CMSensorRecorder isAuthorizedForRecording]) {
        if (!self.recorder)
        {
            self.recorder = [[CMSensorRecorder alloc] init];
        }

        NSTimeInterval interval = 1 * 20;
        [self.recorder recordAccelerometerFor:interval];
    }
}

- (IBAction)read {

    // Check authorizations with boolean
    bool toTest_AccelerometerAvailable = [CMSensorRecorder isAccelerometerRecordingAvailable];
    bool toTest_RecordingAuthorized = [CMSensorRecorder isAuthorizedForRecording];

    // Try to get historical data from the last 2 days
    NSDate *now = [NSDate date];
    NSDate *startDate = [now dateByAddingTimeInterval:-2*24*60*60];
    CMSensorDataList *dataList = [self.recorder accelerometerDataFrom:startDate to:[NSDate date]];
}

On the iOS app side, I asked for the form & fitness authorization.

Debug session gave the following results:

  • boolean toTest_RecordingAuthorized is always equal to true (start & read function) - access to form & fitness was asked in associated iOS app.

  • boolean toTest_AccelerometerAvailable is always equal to false (start & read function)

  • CMSensorDataList *dataList is equal to nil at any time

Tests were made with simulators but also with real devices (iOS 9.0 & watchOS 2.0). Same result!

I guess, as long as isAccelerometerRecordingAvailable returns false, the problem will persist. No idea how to fix it...

Does anyone also experiment this problem and fix it?

like image 968
stunt_man Avatar asked Feb 16 '26 03:02

stunt_man


1 Answers

-2*24*60*60 , You are trying to access last 2 days of data, but according to documentation you can only query 12 hours of data. Read it here: Apple Documentation about CMSensorRecorder

like image 180
Avinash Kumar Gautam Avatar answered Feb 19 '26 22:02

Avinash Kumar Gautam