什么CMErrorDomain错误103。的意思吗?(CMPedometer) - What does CMErrorDomain error 103. mean? (CMPedometer)

- 此内容更新于:2015-12-17
主题:

我挣扎完全让CMPedometer返回任何数据。然而Iconfigure我得到我用斯威夫特和分解查询尽可能简单。我为我的应用程序启用运动检测,没有问题得到HealthKit类似的数据。我一定遗漏了一些关键点简单,但我看不出它是什么!

原文:

I'm struggling totally to get CMPedometer to return any step data. However Iconfigure I get Error Domain=CMErrorDomain Code=103 "The operation couldn’t be completed. (CMErrorDomain error 103.)"

I'm using swift and have broken down the queryPedometerDataFromDate query to be as simple as possible.

    let pedometer = CMPedometer()
    let fromDateString = "2015-01-22"
    let toDateString = "2015-01-23"
    let dateFormatter = NSDateFormatter()
    dateFormatter.dateFormat = "YYYY-MM-DD"
    let fromDate = dateFormatter.dateFromString(fromDateString)
    let toDate = dateFormatter.dateFromString(toDateString)

    pedometer.queryPedometerDataFromDate(fromDate, toDate: toDate) { (data:CMPedometerData!, error:NSError!) -> Void in

        if error == nil {
            println(data)
        } else {
            println(error)
        }
    }

I've enabled motion detection for my app, and have no problem getting similar data out of HealthKit.

I must be missing something simple, but I can't see what it is!

网友:你必须CMPedometer对象定义为财产而不是局部变量

(原文:You have to define CMPedometer's object as property instead of local variable)

解决方案:
经过一天的研究。你必须有您的类的对象作为一个全局变量。如果它是定义为一个局部变量的问题它不会工作。简单地添加在类级别将解决这个问题。
原文:

Ok, so after another day of research. You have to have the CMPedometer object as a global variable for your class. If it's defined as a local variable like in the question it won't work. Simply adding let pedometer = CDPedometer() at the class level will fix this issue.