From 5dd07cc1f44087845c1737d558b3e5dff9487537 Mon Sep 17 00:00:00 2001 From: Lee-sungheon Date: Mon, 14 Oct 2024 19:29:32 +0900 Subject: [PATCH 1/2] Fix build issue due to limited contact permission --- README.md | 2 +- ios/RCTContacts/RCTContacts.mm | 57 +++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5922f951..3ac847f8 100644 --- a/README.md +++ b/README.md @@ -353,7 +353,7 @@ The thumbnailPath is the direct URI for the temp location of the contact's cropp Usage as follows: ```js Contacts.checkPermission().then(permission => { - // Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_DENIED + // Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_LIMITED || Contacts.PERMISSION_DENIED if (permission === 'undefined') { Contacts.requestPermission().then(permission => { // ... diff --git a/ios/RCTContacts/RCTContacts.mm b/ios/RCTContacts/RCTContacts.mm index 019131c4..9378a1a2 100644 --- a/ios/RCTContacts/RCTContacts.mm +++ b/ios/RCTContacts/RCTContacts.mm @@ -60,14 +60,25 @@ - (NSDictionary *)constantsToExport rejecter:(RCTPromiseRejectBlock) __unused reject) { CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else if (authStatus == CNAuthorizationStatusLimited) { - resolve(@"limited"); + + if (@available(iOS 18, *)) { + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else if (authStatus == CNAuthorizationStatusLimited) { + resolve(@"limited"); + } else { + resolve(@"undefined"); + } } else { - resolve(@"undefined"); + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else { + resolve(@"undefined"); + } } } @@ -568,7 +579,7 @@ - (NSString *)getPathForDirectory:(int)directory } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } @@ -606,7 +617,7 @@ -(NSString *) getFilePathForThumbnailImage:(NSString *)recordID } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } @@ -1284,14 +1295,24 @@ - (void)getAll:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)rej - (void)checkPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else if (authStatus == CNAuthorizationStatusLimited) { - resolve(@"limited"); + if (@available(iOS 18, *)) { + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else if (authStatus == CNAuthorizationStatusLimited) { + resolve(@"limited"); + } else { + resolve(@"undefined"); + } } else { - resolve(@"undefined"); + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else { + resolve(@"undefined"); + } } } @@ -1440,7 +1461,7 @@ - (void)getContactById:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBl } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } @@ -1490,7 +1511,7 @@ - (void)getPhotoForId:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBlo } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } From c809039d7311d989587ef698ab5f408fb9794f78 Mon Sep 17 00:00:00 2001 From: Lee-sungheon Date: Mon, 14 Oct 2024 19:51:39 +0900 Subject: [PATCH 2/2] refactor conditional logic for iOS 18 --- ios/RCTContacts/RCTContacts.mm | 81 ++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 34 deletions(-) diff --git a/ios/RCTContacts/RCTContacts.mm b/ios/RCTContacts/RCTContacts.mm index 9378a1a2..feaf0dac 100644 --- a/ios/RCTContacts/RCTContacts.mm +++ b/ios/RCTContacts/RCTContacts.mm @@ -61,24 +61,16 @@ - (NSDictionary *)constantsToExport { CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; - if (@available(iOS 18, *)) { - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else if (authStatus == CNAuthorizationStatusLimited) { + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else if(@available(iOS 18, *)) { + if (authStatus == CNAuthorizationStatusLimited) { resolve(@"limited"); - } else { - resolve(@"undefined"); } } else { - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else { - resolve(@"undefined"); - } + resolve(@"undefined"); } } @@ -579,10 +571,17 @@ - (NSString *)getPathForDirectory:(int)directory } }]; } - else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } + else if(@available(iOS 18, *)) + { + if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + { + resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); + } + } } -(NSString *) getFilePathForThumbnailImage:(NSString *)recordID @@ -617,10 +616,17 @@ -(NSString *) getFilePathForThumbnailImage:(NSString *)recordID } }]; } - else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } + else if(@available(iOS 18, *)) + { + if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + { + resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); + } + } } -(NSDictionary *) getContact:(NSString *)recordID @@ -1295,24 +1301,16 @@ - (void)getAll:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)rej - (void)checkPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts]; - if (@available(iOS 18, *)) { - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else if (authStatus == CNAuthorizationStatusLimited) { + if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ + resolve(@"denied"); + } else if (authStatus == CNAuthorizationStatusAuthorized){ + resolve(@"authorized"); + } else if(@available(iOS 18, *)) { + if (authStatus == CNAuthorizationStatusLimited) { resolve(@"limited"); - } else { - resolve(@"undefined"); } } else { - if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){ - resolve(@"denied"); - } else if (authStatus == CNAuthorizationStatusAuthorized){ - resolve(@"authorized"); - } else { - resolve(@"undefined"); - } + resolve(@"undefined"); } } @@ -1461,10 +1459,17 @@ - (void)getContactById:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBl } }]; } - else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } + else if(@available(iOS 18, *)) + { + if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + { + resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); + } + } } @@ -1511,10 +1516,18 @@ - (void)getPhotoForId:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBlo } }]; } - else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } + else if(@available(iOS 18, *)) + { + if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) + { + resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); + } + + } }