In an application I use HealthKit. I get the walking and running information. I can display the data in log screen but when I want to send the data to view controller with a closure it sends only 10 or 15 rows but not the all. Here how my code looks like.
How can I send the all data to view controller?
Code:
- (void) readStepCounterWithCompletionHandler:(void (^)(BOOL isErrorOccured, NSString *errorDesc, NSArray *sampleArray)) handler {
NSDate *startDate;
NSDate *endDate = [NSDate date];
NSCalendar *calendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
// Use the sample type for step count
HKSampleType *sampleType = [HKSampleType quantityTypeForIdentifier:HKQuantityTypeIdentifierDistanceWalkingRunning];
// Create a predicate to set start/end date bounds of the query
NSPredicate *predicate = [HKQuery predicateForSamplesWithStartDate:startDate endDate:endDate options:HKQueryOptionStrictStartDate];
// Create a sort descriptor for sorting by start date
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:HKSampleSortIdentifierStartDate ascending:false];
HKSampleQuery *query2 = [[HKSampleQuery alloc] initWithSampleType:sampleType predicate:predicate limit:HKObjectQueryNoLimit sortDescriptors:@[sortDescriptor] resultsHandler:^(HKSampleQuery * _Nonnull query, NSArray<__kindof HKSample *> * _Nullable results, NSError * _Nullable error) {
if(error) {
handler(true, error.description, nil);
} else {
NSMutableArray *tempArray = [NSMutableArray new];
for(HKQuantitySample *samples in results) {
[tempArray addObject:samples];
NSLog(@"Samples %@", samples);
}
handler(false, @"", tempArray);
}
}];
// Execute the query
[self.healthStore executeQuery:query2];
}
How can I send the all data to view controller?