|
@@ -6,6 +6,8 @@
|
6
|
6
|
// Copyright © 2016 Yonah Forst. All rights reserved.
|
7
|
7
|
//
|
8
|
8
|
|
|
9
|
+@import Contacts;
|
|
10
|
+
|
9
|
11
|
#import "ReactNativePermissions.h"
|
10
|
12
|
|
11
|
13
|
#import "RCTBridge.h"
|
|
@@ -26,6 +28,11 @@
|
26
|
28
|
|
27
|
29
|
@implementation ReactNativePermissions
|
28
|
30
|
|
|
31
|
++ (BOOL)useContactsFramework
|
|
32
|
+{
|
|
33
|
+ return [[CNContactStore alloc] init] != nil;
|
|
34
|
+}
|
|
35
|
+
|
29
|
36
|
RCT_EXPORT_MODULE();
|
30
|
37
|
@synthesize bridge = _bridge;
|
31
|
38
|
|
|
@@ -127,19 +134,38 @@ RCT_REMAP_METHOD(photoPermissionStatus, photoPermission:(RCTPromiseResolveBlock)
|
127
|
134
|
|
128
|
135
|
RCT_REMAP_METHOD(contactsPermissionStatus, contactsPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
129
|
136
|
{
|
130
|
|
- int status = ABAddressBookGetAuthorizationStatus();
|
131
|
|
- switch (status) {
|
132
|
|
- case kABAuthorizationStatusAuthorized:
|
133
|
|
- return resolve(@(RNPermissionsStatusAuthorized));
|
134
|
|
-
|
135
|
|
- case kABAuthorizationStatusDenied:
|
136
|
|
- return resolve(@(RNPermissionsStatusDenied));
|
137
|
|
-
|
138
|
|
- case kABAuthorizationStatusRestricted:
|
139
|
|
- return resolve(@(RNPermissionsStatusRestricted));
|
140
|
|
-
|
141
|
|
- default:
|
142
|
|
- return resolve(@(RNPermissionsStatusUndetermined));
|
|
137
|
+ if ([ReactNativePermissions useContactsFramework])
|
|
138
|
+ {
|
|
139
|
+ int status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
|
|
140
|
+ switch (status) {
|
|
141
|
+ case CNAuthorizationStatusAuthorized:
|
|
142
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
143
|
+
|
|
144
|
+ case CNAuthorizationStatusDenied:
|
|
145
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
146
|
+
|
|
147
|
+ case CNAuthorizationStatusRestricted:
|
|
148
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
149
|
+
|
|
150
|
+ default:
|
|
151
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
152
|
+ }
|
|
153
|
+ }
|
|
154
|
+ else {
|
|
155
|
+ int status = ABAddressBookGetAuthorizationStatus();
|
|
156
|
+ switch (status) {
|
|
157
|
+ case kABAuthorizationStatusAuthorized:
|
|
158
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
159
|
+
|
|
160
|
+ case kABAuthorizationStatusDenied:
|
|
161
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
162
|
+
|
|
163
|
+ case kABAuthorizationStatusRestricted:
|
|
164
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
165
|
+
|
|
166
|
+ default:
|
|
167
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
168
|
+ }
|
143
|
169
|
}
|
144
|
170
|
}
|
145
|
171
|
|