0

我在我的 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)

}
4

1 回答 1

1

手表上的 HealthKit 仅提供最近 7 天的数据。在此之前创建的任何锻炼都只能在手机上进行。有关更多信息,请参阅HKHealthStore 参考

于 2015-09-24T22:00:03.013 回答