CMMotionActivityManager queryActivityStarting数据不准确

时间:2018-01-03 12:09:05

标签: swift swift3 cmmotionmanager

我想在过去24小时内列出我的活动,但我收到的一些数据完全无关紧要。
例如,当我正在睡觉并且手机完全处于静止状态时,CMMotionActivityManager会将状态恢复为行走
这是我的代码:

aktivite.queryActivityStarting(from: Date.init().addingTimeInterval(-60.0*60.0*24.0), 
                               to: Date.init(), 
                               to: OperationQueue.main) {(activityList, error) in
    var aktiviteString = ""
    for (activity) in activityList! {
        if (activity.stationary) {
            aktiviteString = "Stationary"
        }
        else if (activity.walking) {
            aktiviteString = "Walking"
        }
        else if (activity.running) {
            aktiviteString = "Running"
        }
        else if (activity.automotive) {
            aktiviteString = "Automotive"
        }
        else if (activity.cycling) {
            aktiviteString = "Cycling"
        }
        else {
            aktiviteString = "Unknown"
        }
        if (self.lastActivity == aktiviteString) {
            continue;
        }
        if (activity.confidence == .low) { continue }
        if (activity.confidence == .medium) { continue }
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "hh:mm:ss"
        let dateString:String! = dateFormatter.string(from: activity.startDate)
        print(aktiviteString + "@" + dateString)
        self.lastActivity = aktiviteString

    }
}

以下是上述方法返回的令人困惑的项目:

Stationary@02:02:11
Unknown@02:02:46
Stationary@02:02:56
Unknown@02:03:16
Stationary@02:03:21
Walking@02:04:51
Unknown@02:05:26
Walking@02:05:48
Unknown@02:06:23
Walking@02:06:40
Unknown@02:07:05
Walking@02:07:08
Unknown@02:20:18
Walking@02:20:46

谢谢。

0 个答案:

没有答案