计步器无法正常工作,iPhone 5也无法使用Apple Watch

时间:2017-11-05 04:36:53

标签: ios swift

我也在WatchKit扩展中使用相同的代码,但我得到同样的错误,无法找出问题所在,我还检查了iPhone 5,5s,Apple Watch中的代码

    self.manager.deviceMotionUpdateInterval = 0.1
    let fromDateString = "2017-09-1"
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "YYYY-MM-DD"
    let fromDate = dateFormatter.date(from: fromDateString)



    if(CMMotionActivityManager.isActivityAvailable()){

        let mainQ = OperationQueue.main

        self.activityManager.startActivityUpdates(to: mainQ, withHandler: { (data: CMMotionActivity!) -> Void in

            DispatchQueue.main.async(execute: {
                if(data.stationary == true){
                    self.activityState.text = "Stationary"
                } else if (data.walking == true){
                    self.activityState.text = "Walking"
                } else if (data.running == true){
                    self.activityState.text = "Running"
                } else if (data.automotive == true){
                    self.activityState.text = "Automotive"
                }
            })
        })
    }

////////////// Plz看着我做错了//////////

    if(CMPedometer.isStepCountingAvailable()) {

        self.pedoMeter.queryPedometerData(from: fromDate!, to: Date.init()) { (data : CMPedometerData!, error) -> Void in

            DispatchQueue.main.async(execute: {

                if(error == nil){
                    self.steps.text = "\(data.numberOfSteps)"
                }
            })
        }
    }

    let todya = Date.init()
    self.pedoMeter.startUpdates(from: todya) { (data: CMPedometerData!, error) -> Void in

        DispatchQueue.main.async(execute: {

/ *****我每次都会收到此错误

可选(“操作无法完成。(CMErrorDomain错误104。)”)

* /

            if(error == nil){
                self.steps.text = "\(data.numberOfSteps)"
            }
        })
    }

1 个答案:

答案 0 :(得分:0)

实际错误是Apple的。 isStepCountingAvailable应该已返回false,因为这些设备没有计步器功能。