react-native-contacts 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/index.ts +3 -7
- package/ios/RCTContacts/RCTContacts.mm +43 -4
- package/package.json +1 -1
- package/src/NativeContacts.ts +3 -3
- package/type.ts +2 -0
package/README.md
CHANGED
|
@@ -353,7 +353,7 @@ The thumbnailPath is the direct URI for the temp location of the contact's cropp
|
|
|
353
353
|
Usage as follows:
|
|
354
354
|
```js
|
|
355
355
|
Contacts.checkPermission().then(permission => {
|
|
356
|
-
// Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_DENIED
|
|
356
|
+
// Contacts.PERMISSION_AUTHORIZED || Contacts.PERMISSION_UNDEFINED || Contacts.PERMISSION_LIMITED || Contacts.PERMISSION_DENIED
|
|
357
357
|
if (permission === 'undefined') {
|
|
358
358
|
Contacts.requestPermission().then(permission => {
|
|
359
359
|
// ...
|
|
@@ -362,6 +362,9 @@ Contacts.checkPermission().then(permission => {
|
|
|
362
362
|
if (permission === 'authorized') {
|
|
363
363
|
// yay!
|
|
364
364
|
}
|
|
365
|
+
if (permission === 'limited') {
|
|
366
|
+
// ...
|
|
367
|
+
}
|
|
365
368
|
if (permission === 'denied') {
|
|
366
369
|
// x.x
|
|
367
370
|
}
|
package/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NativeModules } from "react-native";
|
|
2
2
|
import NativeContacts from "./src/NativeContacts";
|
|
3
|
-
import { Contact } from "./type";
|
|
3
|
+
import { Contact, PermissionType } from "./type";
|
|
4
4
|
|
|
5
5
|
const isTurboModuleEnabled = global.__turboModuleProxy != null;
|
|
6
6
|
const Contacts = isTurboModuleEnabled ? NativeContacts : NativeModules.Contacts;
|
|
@@ -73,15 +73,11 @@ async function getContactsByEmailAddress(
|
|
|
73
73
|
return Contacts.getContactsByEmailAddress(emailAddress);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
async function checkPermission(): Promise<
|
|
77
|
-
"authorized" | "denied" | "undefined"
|
|
78
|
-
> {
|
|
76
|
+
async function checkPermission(): Promise<PermissionType> {
|
|
79
77
|
return Contacts.checkPermission();
|
|
80
78
|
}
|
|
81
79
|
|
|
82
|
-
async function requestPermission(): Promise<
|
|
83
|
-
"authorized" | "denied" | "undefined"
|
|
84
|
-
> {
|
|
80
|
+
async function requestPermission(): Promise<PermissionType> {
|
|
85
81
|
return Contacts.requestPermission();
|
|
86
82
|
}
|
|
87
83
|
|
|
@@ -44,6 +44,7 @@ RCT_EXPORT_MODULE();
|
|
|
44
44
|
return @{
|
|
45
45
|
@"PERMISSION_DENIED": @"denied",
|
|
46
46
|
@"PERMISSION_AUTHORIZED": @"authorized",
|
|
47
|
+
@"PERMISSION_LIMITED": @"limited",
|
|
47
48
|
@"PERMISSION_UNDEFINED": @"undefined"
|
|
48
49
|
};
|
|
49
50
|
}
|
|
@@ -59,10 +60,15 @@ RCT_EXPORT_METHOD(checkPermission:(RCTPromiseResolveBlock) resolve
|
|
|
59
60
|
rejecter:(RCTPromiseRejectBlock) __unused reject)
|
|
60
61
|
{
|
|
61
62
|
CNAuthorizationStatus authStatus = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
|
|
63
|
+
|
|
62
64
|
if (authStatus == CNAuthorizationStatusDenied || authStatus == CNAuthorizationStatusRestricted){
|
|
63
65
|
resolve(@"denied");
|
|
64
66
|
} else if (authStatus == CNAuthorizationStatusAuthorized){
|
|
65
67
|
resolve(@"authorized");
|
|
68
|
+
} else if(@available(iOS 18, *)) {
|
|
69
|
+
if (authStatus == CNAuthorizationStatusLimited) {
|
|
70
|
+
resolve(@"limited");
|
|
71
|
+
}
|
|
66
72
|
} else {
|
|
67
73
|
resolve(@"undefined");
|
|
68
74
|
}
|
|
@@ -565,10 +571,17 @@ RCT_EXPORT_METHOD(getPhotoForId:(nonnull NSString *)recordID resolver:(RCTPromis
|
|
|
565
571
|
}
|
|
566
572
|
}];
|
|
567
573
|
}
|
|
568
|
-
else if(
|
|
574
|
+
else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
|
|
569
575
|
{
|
|
570
576
|
resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]);
|
|
571
577
|
}
|
|
578
|
+
else if(@available(iOS 18, *))
|
|
579
|
+
{
|
|
580
|
+
if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)
|
|
581
|
+
{
|
|
582
|
+
resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
572
585
|
}
|
|
573
586
|
|
|
574
587
|
-(NSString *) getFilePathForThumbnailImage:(NSString *)recordID
|
|
@@ -603,10 +616,17 @@ RCT_EXPORT_METHOD(getContactById:(nonnull NSString *)recordID resolver:(RCTPromi
|
|
|
603
616
|
}
|
|
604
617
|
}];
|
|
605
618
|
}
|
|
606
|
-
else if(
|
|
619
|
+
else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
|
|
607
620
|
{
|
|
608
621
|
resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]);
|
|
609
622
|
}
|
|
623
|
+
else if(@available(iOS 18, *))
|
|
624
|
+
{
|
|
625
|
+
if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)
|
|
626
|
+
{
|
|
627
|
+
resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
610
630
|
}
|
|
611
631
|
|
|
612
632
|
-(NSDictionary *) getContact:(NSString *)recordID
|
|
@@ -1285,6 +1305,10 @@ RCT_EXPORT_METHOD(writePhotoToPath:(nonnull NSString *)path resolver:(RCTPromise
|
|
|
1285
1305
|
resolve(@"denied");
|
|
1286
1306
|
} else if (authStatus == CNAuthorizationStatusAuthorized){
|
|
1287
1307
|
resolve(@"authorized");
|
|
1308
|
+
} else if(@available(iOS 18, *)) {
|
|
1309
|
+
if (authStatus == CNAuthorizationStatusLimited) {
|
|
1310
|
+
resolve(@"limited");
|
|
1311
|
+
}
|
|
1288
1312
|
} else {
|
|
1289
1313
|
resolve(@"undefined");
|
|
1290
1314
|
}
|
|
@@ -1435,10 +1459,17 @@ RCT_EXPORT_METHOD(writePhotoToPath:(nonnull NSString *)path resolver:(RCTPromise
|
|
|
1435
1459
|
}
|
|
1436
1460
|
}];
|
|
1437
1461
|
}
|
|
1438
|
-
else if(
|
|
1462
|
+
else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
|
|
1439
1463
|
{
|
|
1440
1464
|
resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]);
|
|
1441
1465
|
}
|
|
1466
|
+
else if(@available(iOS 18, *))
|
|
1467
|
+
{
|
|
1468
|
+
if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)
|
|
1469
|
+
{
|
|
1470
|
+
resolve([self getContact:recordID addressBook:contactStore withThumbnails:false]);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1442
1473
|
}
|
|
1443
1474
|
|
|
1444
1475
|
|
|
@@ -1485,10 +1516,18 @@ RCT_EXPORT_METHOD(writePhotoToPath:(nonnull NSString *)path resolver:(RCTPromise
|
|
|
1485
1516
|
}
|
|
1486
1517
|
}];
|
|
1487
1518
|
}
|
|
1488
|
-
else if(
|
|
1519
|
+
else if([CNContactStore authorizationStatusForEntityType:entityType]== CNAuthorizationStatusAuthorized)
|
|
1489
1520
|
{
|
|
1490
1521
|
resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]);
|
|
1491
1522
|
}
|
|
1523
|
+
else if(@available(iOS 18, *))
|
|
1524
|
+
{
|
|
1525
|
+
if([CNContactStore authorizationStatusForEntityType:entityType] == CNAuthorizationStatusLimited)
|
|
1526
|
+
{
|
|
1527
|
+
resolve([self getFilePathForThumbnailImage:recordID addressBook:contactStore]);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
}
|
|
1492
1531
|
}
|
|
1493
1532
|
|
|
1494
1533
|
|
package/package.json
CHANGED
package/src/NativeContacts.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
|
|
2
2
|
import { TurboModuleRegistry } from "react-native";
|
|
3
|
-
import { Contact } from "../type";
|
|
3
|
+
import { Contact, PermissionType } from "../type";
|
|
4
4
|
|
|
5
5
|
export interface Spec extends TurboModule {
|
|
6
6
|
getAll: () => Promise<any>;
|
|
@@ -18,8 +18,8 @@ export interface Spec extends TurboModule {
|
|
|
18
18
|
getContactsMatchingString: (str: string) => Promise<Contact[]>;
|
|
19
19
|
getContactsByPhoneNumber: (phoneNumber: string) => Promise<Contact[]>;
|
|
20
20
|
getContactsByEmailAddress: (emailAddress: string) => Promise<Contact[]>;
|
|
21
|
-
checkPermission: () => Promise<
|
|
22
|
-
requestPermission: () => Promise<
|
|
21
|
+
checkPermission: () => Promise<PermissionType>;
|
|
22
|
+
requestPermission: () => Promise<PermissionType>;
|
|
23
23
|
writePhotoToPath: (contactId: string, file: string) => Promise<boolean>;
|
|
24
24
|
iosEnableNotesUsage: (enabled: boolean) => void;
|
|
25
25
|
}
|