0

假设我们在 healthkit 中有一些由 iphone 自动检测并写入 healthkit 的步骤数据。我们有一些步骤数据是由用户手动输入的。现在我可以使用此代码区分这些步骤

let type = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierStepCount) // The type of data we are requesting

    let date = NSDate()
    let cal = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
    let newDate = cal.startOfDayForDate(date)
    print(newDate)
    let predicate = HKQuery.predicateForSamplesWithStartDate(newDate, endDate: NSDate(), options: .None) // Our search predicate which will fetch all steps taken today

    let query = HKSampleQuery(sampleType: type!, predicate: predicate, limit: 0, sortDescriptors: nil) { query, results, error in
        var steps: Double = 0

        //if result.metadata!["HKWasUserEntered"]! == 1{
        if results?.count > 0
        {
            for result in results as! [HKQuantitySample]
            {
                print("Steps \(result.quantity.doubleValueForUnit(HKUnit.countUnit()))")
                print()
                // checking and truncating manually added steps
                if result.metadata != nil {

                }
                else{
                    steps += result.quantity.doubleValueForUnit(HKUnit.countUnit())
                }

            }
            print(steps)
        }

        completion(steps, error)
        //}
    }

    executeQuery(query)

但是让我们说如果其他一些应用程序像一些健身应用程序一样将一些步骤的数据写入healthkit。

在此处输入图像描述

现在我可以读取带有设备图标(自动记录)的步骤,但是我如何也可以读取带有 UP 图标的步骤?

(UP) 是 JawBone 的健身应用程序。

4

0 回答 0