WatchKit App 只返回一些 HealthKit 数据

WatchKit App only returning some HealthKit Data

我的 IOS 应用程序和 WatchKit 应用程序 (Xcode 7 GM) 中都有以下方法 运行。 IOS 应用 returns 我的所有 运行 锻炼,但是 Watchkit 应用 returns 仅前 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)

}

手表上的 HealthKit 只能提供最近 7 天的数据。早于此创建的任何锻炼将仅在 phone 上。有关详细信息,请参阅 HKHealthStore reference