瀏覽代碼

add ios9 Contacts framework check

Joe Noon 8 年之前
父節點
當前提交
734fb1aebd
共有 2 個檔案被更改,包括 41 行新增14 行删除
  1. 39
    13
      ReactNativePermissions.m
  2. 2
    1
      ReactNativePermissions.podspec

+ 39
- 13
ReactNativePermissions.m 查看文件

@@ -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
 

+ 2
- 1
ReactNativePermissions.podspec 查看文件

@@ -12,7 +12,8 @@ Pod::Spec.new do |s|
12 12
   s.author              = package['author']
13 13
   s.source              = { :git => 'https://github.com/yonahforst/react-native-permissions.git', :tag => s.version }
14 14
 
15
-  s.platform            = :ios, '8.0'
15
+  s.platform              = :ios, '9.0'
16
+  s.ios.deployment_target = '8.0'
16 17
 
17 18
   s.dependency 'React'
18 19