diff --git a/README.md b/README.md index 71b1e8a5..5922f951 100644 --- a/README.md +++ b/README.md @@ -362,6 +362,9 @@ Contacts.checkPermission().then(permission => { if (permission === 'authorized') { // yay! } + if (permission === 'limited') { + // ... + } if (permission === 'denied') { // x.x } diff --git a/index.ts b/index.ts index 52f58766..9f154718 100644 --- a/index.ts +++ b/index.ts @@ -1,6 +1,6 @@ import { NativeModules } from "react-native"; import NativeContacts from "./src/NativeContacts"; -import { Contact } from "./type"; +import { Contact, PermissionType } from "./type"; const isTurboModuleEnabled = global.__turboModuleProxy != null; const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts; @@ -73,15 +73,11 @@ async function getContactsByEmailAddress( return Contacts.getContactsByEmailAddress(emailAddress); } -async function checkPermission(): Promise< - "authorized" | "denied" | "undefined" -> { +async function checkPermission(): Promise { return Contacts.checkPermission(); } -async function requestPermission(): Promise< - "authorized" | "denied" | "undefined" -> { +async function requestPermission(): Promise { return Contacts.requestPermission(); } diff --git a/ios/.DS_Store b/ios/.DS_Store index 71ee4a4b..6c905cf5 100644 Binary files a/ios/.DS_Store and b/ios/.DS_Store differ diff --git a/ios/RCTContacts/RCTContacts.mm b/ios/RCTContacts/RCTContacts.mm index 7275a1aa..019131c4 100644 --- a/ios/RCTContacts/RCTContacts.mm +++ b/ios/RCTContacts/RCTContacts.mm @@ -44,6 +44,7 @@ - (NSDictionary *)constantsToExport return @{ @"PERMISSION_DENIED": @"denied", @"PERMISSION_AUTHORIZED": @"authorized", + @"PERMISSION_LIMITED": @"limited", @"PERMISSION_UNDEFINED": @"undefined" }; } @@ -63,6 +64,8 @@ - (NSDictionary *)constantsToExport resolve(@"denied"); } else if (authStatus == CNAuthorizationStatusAuthorized){ resolve(@"authorized"); + } else if (authStatus == CNAuthorizationStatusLimited) { + resolve(@"limited"); } else { resolve(@"undefined"); } @@ -565,7 +568,7 @@ - (NSString *)getPathForDirectory:(int)directory } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) + else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } @@ -603,7 +606,7 @@ -(NSString *) getFilePathForThumbnailImage:(NSString *)recordID } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) + else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } @@ -1285,6 +1288,8 @@ - (void)checkPermission:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseReject resolve(@"denied"); } else if (authStatus == CNAuthorizationStatusAuthorized){ resolve(@"authorized"); + } else if (authStatus == CNAuthorizationStatusLimited) { + resolve(@"limited"); } else { resolve(@"undefined"); } @@ -1435,7 +1440,7 @@ - (void)getContactById:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBl } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) + else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) { resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]); } @@ -1485,7 +1490,7 @@ - (void)getPhotoForId:(nonnull NSString *)recordID resolve:(RCTPromiseResolveBlo } }]; } - else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized) + else if( [CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized || [CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)) { resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]); } diff --git a/src/NativeContacts.ts b/src/NativeContacts.ts index 9b4b76b1..60880533 100644 --- a/src/NativeContacts.ts +++ b/src/NativeContacts.ts @@ -1,6 +1,6 @@ import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport"; import { TurboModuleRegistry } from "react-native"; -import { Contact } from "../type"; +import { Contact, PermissionType } from "../type"; export interface Spec extends TurboModule { getAll: () => Promise; @@ -18,8 +18,8 @@ export interface Spec extends TurboModule { getContactsMatchingString: (str: string) => Promise; getContactsByPhoneNumber: (phoneNumber: string) => Promise; getContactsByEmailAddress: (emailAddress: string) => Promise; - checkPermission: () => Promise; - requestPermission: () => Promise; + checkPermission: () => Promise; + requestPermission: () => Promise; writePhotoToPath: (contactId: string, file: string) => Promise; iosEnableNotesUsage: (enabled: boolean) => void; } diff --git a/type.ts b/type.ts index 1e45d83a..cbb5e23c 100644 --- a/type.ts +++ b/type.ts @@ -60,3 +60,5 @@ export interface Contact { urlAddresses: UrlAddress[]; note: string; } + +export type PermissionType = 'authorized' | 'limited' | 'denied' | 'undefined' \ No newline at end of file