I want to query the apple ring's data today, but when i write the code like below, it will crash. It seem that only crash in IOS13.
here is the ternimate information:
** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unexpected dataType of class HKActivitySummaryType for startDate predicate' terminating with uncaught exception of type NSException CoreSimulator 776.3 - Device: iPhone 8 (65B9F36C-53AA-41C4-9F07-0FE9D0742897) - Runtime: iOS 13.5 (17F61) - DeviceType: iPhone 8
NSDate *now = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar
components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond)
fromDate:now];
//
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
NSDate *dayStart = [calendar dateFromComponents:components];
//
[components setHour:24];
[components setMinute:0];
[components setSecond:1];
NSDate *dayEnd = [calendar dateFromComponents:components];
NSLog(@"query summary from %@ to %@", dayStart, dayEnd);
NSPredicate *predicateDate = [HKQuery predicateForSamplesWithStartDate:dayStart
endDate:dayEnd
options:HKQueryOptionStrictStartDate | HKQueryOptionStrictEndDate];
HKActivitySummaryQuery *summaryQuery = [[HKActivitySummaryQuery alloc]
initWithPredicate:predicateDate
resultsHandler:^(HKActivitySummaryQuery *_Nonnull query, NSArray<HKActivitySummary *> *_Nullable activitySummaries, NSError *_Nullable error) {
NSLog(@"get query summary count:%lu", (unsigned long)activitySummaries.count);
}];
[self.healthStore executeQuery:summaryQuery];