0

I have the below method running in both my IOS app and my WatchKit App (Xcode 7 GM). The IOS app returns all of my running workouts, however the Watchkit app returns only the first 2 running workouts.

Any idea?

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)

}
Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
GarySabo
  • 5,806
  • 5
  • 49
  • 124
  • What is the source associated with the workouts? Which device were the workouts saved on? How old are the workouts? – Allan Sep 23 '15 at 21:36
  • Saved on the watch and they were on the past 2 months. New workouts show up just not those older ones. – GarySabo Sep 23 '15 at 21:47

1 Answers1

2

Only the last 7 days worth of data is available from HealthKit on the watch. Any workouts that were created earlier than that will only be on the phone. See the HKHealthStore reference for more information.

kanobius
  • 756
  • 9
  • 12
Allan
  • 7,039
  • 1
  • 16
  • 26