CMPedometer queryPedometerDataFromDate returns error 103

耗尽温柔 提交于 2019-12-13 11:46:05

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/27501798/cmpedometer-querypedometerdatafromdate-returns-error-103

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!