CMPedometer queryPedometerDataFromDate返回错误103 [英] CMPedometer queryPedometerDataFromDate returns error 103
问题描述
我正在尝试使用iOS 8.1.2对iPhone 6上的计步器缓存进行查询,我使用的是Objective-c,我已经导入了CoreMotion框架,并将其包含在项目中,代码如下所示
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);
}
}];
这给我错误:错误Domain = CMErrorDomain Code = 103操作无法完成。(CMErrorDomain错误103.)
This gives me the error: Error Domain=CMErrorDomain Code=103 "The operation couldn’t be completed. (CMErrorDomain error 103.)"
如果我像Swift一样在Swift中做同样的事情
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 ?
推荐答案
您应该将CMPedometer变量保存为您的类的属性,而不是局部变量。然后它会起作用。
You should hold your CMPedometer variables as a property of you class, not as Local variables. And then it will work.
这篇关于CMPedometer queryPedometerDataFromDate返回错误103的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!