【问题标题】:WatchKit App only returning some HealthKit DataWatchKit App 仅返回一些 HealthKit 数据
【发布时间】:2015-09-23 14:20:37
【问题描述】:

我的 IOS 应用程序和 WatchKit 应用程序(Xcode 7 GM)中都运行了以下方法。 IOS 应用程序返回我所有的跑步锻炼,但是 Watchkit 应用程序只返回前 2 次跑步锻炼。

有什么想法吗?

func readRunningWorkOuts(completion: (([AnyObject]!, NSError!) -> Void)!) {

    // 1. Predicate to read only running workouts
    let predicate =  HKQuery.predicateForWorkoutsWithWorkoutActivityType(HKWorkoutActivityType.Running)
    // 2. Order the workouts by date
    let sortDescriptor = NSSortDescriptor(key:HKSampleSortIdentifierStartDate, ascending: false)
    // 3. Create the query
    let sampleQuery = HKSampleQuery(sampleType: HKWorkoutType.workoutType(), predicate: predicate, limit: 0, sortDescriptors: [sortDescriptor])
        { (sampleQuery, results, error ) -> Void in

            if let queryError = error {
                print( "There was an error while reading the samples: \(queryError.localizedDescription)")
            }
            completion(results,error)
    }
    // 4. Execute the query
    healthKitStore.executeQuery(sampleQuery)

}

【问题讨论】:

  • 与锻炼相关的来源是什么?锻炼保存在哪个设备上?锻炼多久了?
  • 保存在手表上,它们是过去 2 个月的数据。新的锻炼不会出现在那些旧的锻炼中。

标签: ios swift watchkit healthkit hksamplequery


【解决方案1】:

手表上的 HealthKit 仅提供最近 7 天的数据。在此之前创建的任何锻炼都只会在手机上。请参阅HKHealthStore reference 了解更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2015-04-10
    • 2016-02-08
    相关资源
    最近更新 更多