Skip to content

Commit

Permalink
Merge pull request #757 from Lee-sungheon/master
Browse files Browse the repository at this point in the history
Fix build issue due to limited contact permission
  • Loading branch information
morenoh149 authored Oct 15, 2024
2 parents bf46da1 + c809039 commit ffddfd2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
// ...
Expand Down
50 changes: 42 additions & 8 deletions ios/RCTContacts/RCTContacts.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ - (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");
} else if(@available(iOS 18, *)) {
if (authStatus == CNAuthorizationStatusLimited) {
resolve(@"limited");
}
} else {
resolve(@"undefined");
}
Expand Down Expand Up @@ -568,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
Expand Down Expand Up @@ -606,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
Expand Down Expand Up @@ -1288,8 +1305,10 @@ - (void)checkPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseReject
resolve(@"denied");
} else if (authStatus == CNAuthorizationStatusAuthorized){
resolve(@"authorized");
} else if (authStatus == CNAuthorizationStatusLimited) {
resolve(@"limited");
} else if(@available(iOS 18, *)) {
if (authStatus == CNAuthorizationStatusLimited) {
resolve(@"limited");
}
} else {
resolve(@"undefined");
}
Expand Down Expand Up @@ -1440,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]);
}
}
}


Expand Down Expand Up @@ -1490,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]);
}

}
}


Expand Down

0 comments on commit ffddfd2

Please sign in to comment.