From abf36e95609a013d82ac2e58ec132ad9f965a978 Mon Sep 17 00:00:00 2001 From: Bryan Soriano Date: Mon, 11 Nov 2024 18:47:09 -0500 Subject: [PATCH] Fix healthkit support for iOS > 16.1 --- .../applesimutils/SetHealthKitPermission.m | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/applesimutils/applesimutils/SetHealthKitPermission.m b/applesimutils/applesimutils/SetHealthKitPermission.m index d9588b3..9c29339 100644 --- a/applesimutils/applesimutils/SetHealthKitPermission.m +++ b/applesimutils/applesimutils/SetHealthKitPermission.m @@ -191,9 +191,25 @@ + (BOOL)setHealthKitPermission:(HealthKitPermissionStatus)permission forBundleId } else { + NSMutableString* query; + NSMutableString* values; + NSMutableDictionary* baseParams; + if (osVersion.majorVersion > 16 || (osVersion.majorVersion == 16 && osVersion.minorVersion > 1)) + { + query = @"source_id, object_type, status, request, mode, date_modified, modification_epoch, provenance, deleted_object_anchor, object_limit_anchor, object_limit_modified, sync_identity".mutableCopy; + values = @":source_id, :object_type, :status, :request, :mode, :date_modified, :modification_epoch, :provenance, :deleted_object_anchor, :object_limit_anchor, :object_limit_modified, :sync_identity".mutableCopy; + baseParams = [@{@"source_id": rowID, @"status": permission == HealthKitPermissionStatusAllow ? @101 : @104, @"request": @203, @"mode": @0, @"date_modified": @(NSDate.date.timeIntervalSinceReferenceDate), @"modification_epoch": @1, @"provenance": @0, @"deleted_object_anchor": @0, @"object_limit_anchor": @0, @"object_limit_modified": NSNull.null, @"sync_identity": @1} mutableCopy]; + } + else + { + query = @"source_id, object_type, status, request, mode, date_modified, modification_epoch, provenance, deleted_object_anchor, object_limit_anchor, object_limit_modified".mutableCopy; + values = @":source_id, :object_type, :status, :request, :mode, :date_modified, :modification_epoch, :provenance, :deleted_object_anchor, :object_limit_anchor, :object_limit_modified".mutableCopy; + baseParams = [@{@"source_id": rowID, @"status": permission == HealthKitPermissionStatusAllow ? @101 : @104, @"request": @203, @"mode": @0, @"date_modified": @(NSDate.date.timeIntervalSinceReferenceDate), @"modification_epoch": @1, @"provenance": @0, @"deleted_object_anchor": @0, @"object_limit_anchor": @0, @"object_limit_modified": NSNull.null} mutableCopy]; + } for(int i = 0; i < 200; i++) { - if([db executeUpdate:@"insert into authorization (source_id, object_type, status, request, mode, date_modified, modification_epoch, provenance, deleted_object_anchor, object_limit_anchor, object_limit_modified) VALUES (:source_id, :object_type, :status, :request, :mode, :date_modified, :modification_epoch, :provenance, :deleted_object_anchor, :object_limit_anchor, :object_limit_modified)" withParameterDictionary:@{@"source_id": rowID, @"object_type": @(i), @"status": permission == HealthKitPermissionStatusAllow ? @101 : @104, @"request": @203, @"mode": @0, @"date_modified": @(NSDate.date.timeIntervalSinceReferenceDate), @"modification_epoch": @1, @"provenance": @0, @"deleted_object_anchor": @0, @"object_limit_anchor": @0, @"object_limit_modified": NSNull.null}] == NO) + baseParams[@"object_type"] = @(i); + if ([db executeUpdate:[NSString stringWithFormat:@"insert into authorization (%@) VALUES (%@)", query, values] withParameterDictionary:baseParams] == NO) { logcontinue_query_error(db); }