Thomas
Thomas

Reputation: 131

CMPedometer queryPedometerDataFromDate returns error 103

I'm trying to do a query to the pedometer cache on an iPhone 6 with iOS 8.1.2, I'm using objective-c, I have imported CoreMotion framework and included it in the project the code looks like this

NSDate *startDate = [[NSDate date] dateByAddingTimeInterval:-60*60*12];
NSDate *endDate = [NSDate date];
CMPedometer *pedo = [[CMPedometer alloc]init];
[pedo queryPedometerDataFromDate:startDate toDate:endDate withHandler:^(CMPedometerData *pedometerData, NSError *error)
 {
     if (error)
     {
         NSLog(@"error: %@", error);
     }
}];

This gives me the error: Error Domain=CMErrorDomain Code=103 "The operation couldn’t be completed. (CMErrorDomain error 103.)"

If I do the exact same thing in Swift like this

var dateString = "2014-12-15"
    var dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "YYYY-MM-DD"

    var startDate = dateFormatter.dateFromString(dateString)
    var endDate = NSDate()

    pedometer.queryPedometerDataFromDate(startDate, toDate: endDate){
        (data, error) -> Void in
        if error != nil
        {
            println("There was an error requesting data from the pedometer: \(error)")
        }
        else
        {
            println(data)
        }
    }

I get the pedometer data and no errors.

In both cases I accept the popup telling me to accept the tracking physical activity. I have double checked that the app has read access to physical activity data under anonymity settings.

Can anyone explain what I'm doing wrong ?

Upvotes: 6

Views: 4288

Answers (1)

shadox
shadox

Reputation: 1003

You should hold your CMPedometer variables as a property of you class, not as Local variables. And then it will work.

Upvotes: 10

Related Questions