Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 910
Thomas Avatar asked Dec 16 '14 09:12

Thomas


1 Answers

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

like image 50
shadox Avatar answered Sep 21 '22 10:09

shadox