CMPedometerPedometerDataFromDate request returns error 103

I'm trying to query the pedometer cache on iPhone 6 with iOS 8.1.2, I use objective-c, I imported the 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 an error: Error Domain = CMErrorDomain Code = 103 "Operation could not be completed (CMErrorDomain error 103.)"

If I do the same 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 pedometer data and no errors.

In both cases, I accept a popup telling me to accept tracking physical activity. I double-checked that the application has read access to physical activity data in anonymity settings.

Can someone explain what I'm doing wrong?

+6
source share
1 answer

You should store CMPedometer variables as a property of your class, and not as local variables. And then it will work.

+10
source

Source: https://habr.com/ru/post/979687/


All Articles