Browse Source

Fix RN import priority, favoring newest version of RN

Tikhon Botchkarev 7 years ago
parent
commit
008bc688ec
3 changed files with 40 additions and 32 deletions
  1. 5
    3
      RCTConvert+RNPStatus.h
  2. 5
    3
      ReactNativePermissions.h
  3. 30
    26
      ReactNativePermissions.m

+ 5
- 3
RCTConvert+RNPStatus.h View File

6
 //  Copyright © 2016 Yonah Forst. All rights reserved.
6
 //  Copyright © 2016 Yonah Forst. All rights reserved.
7
 //
7
 //
8
 
8
 
9
-#if __has_include("RCTConvert.h")
10
-  #import "RCTConvert.h"
11
-#else
9
+#if __has_include(<React/RCTConvert.h>)
12
   #import <React/RCTConvert.h>
10
   #import <React/RCTConvert.h>
11
+#elif __has_include("React/RCTConvert.h")
12
+  #import "React/RCTConvert.h"
13
+#else
14
+  #import "RCTConvert.h"
13
 #endif
15
 #endif
14
 
16
 
15
 static NSString* RNPStatusUndetermined = @"undetermined";
17
 static NSString* RNPStatusUndetermined = @"undetermined";

+ 5
- 3
ReactNativePermissions.h View File

6
 //  Copyright © 2016 Yonah Forst. All rights reserved.
6
 //  Copyright © 2016 Yonah Forst. All rights reserved.
7
 //
7
 //
8
 
8
 
9
-#if __has_include("RCTBridgeModule.h")
10
-  #import "RCTBridgeModule.h"
11
-#else
9
+#if __has_include(<React/RCTBridgeModule.h>)
12
   #import <React/RCTBridgeModule.h>
10
   #import <React/RCTBridgeModule.h>
11
+#elif __has_include("React/RCTBridgeModule.h")
12
+  #import "React/RCTBridgeModule.h"
13
+#else
14
+  #import "RCTBridgeModule.h"
13
 #endif
15
 #endif
14
 
16
 
15
 @interface ReactNativePermissions : NSObject <RCTBridgeModule>
17
 @interface ReactNativePermissions : NSObject <RCTBridgeModule>

+ 30
- 26
ReactNativePermissions.m View File

12
 
12
 
13
 #if __has_include(<React/RCTBridge.h>)
13
 #if __has_include(<React/RCTBridge.h>)
14
   #import <React/RCTBridge.h>
14
   #import <React/RCTBridge.h>
15
-#elif __has_include("RCTBridge.h")
16
-  #import "RCTBridge.h"
17
-#else
15
+#elif __has_include("React/RCTBridge.h")
18
   #import "React/RCTBridge.h"
16
   #import "React/RCTBridge.h"
17
+#else
18
+  #import "RCTBridge.h"
19
 #endif
19
 #endif
20
 
20
 
21
 
21
 
22
-#if __has_include("RCTConvert.h")
23
-  #import "RCTConvert.h"
24
-#else
22
+#if __has_include(<React/RCTConvert.h>)
25
   #import <React/RCTConvert.h>
23
   #import <React/RCTConvert.h>
24
+#elif __has_include("React/RCTConvert.h")
25
+  #import "React/RCTConvert.h"
26
+#else
27
+  #import "RCTConvert.h"
26
 #endif
28
 #endif
27
 
29
 
28
-#if __has_include("RCTEventDispatcher.h")
29
-  #import "RCTEventDispatcher.h"
30
-#else
30
+#if __has_include(<React/RCTEventDispatcher.h>)
31
   #import <React/RCTEventDispatcher.h>
31
   #import <React/RCTEventDispatcher.h>
32
+#elif __has_include("React/RCTEventDispatcher.h")
33
+  #import "React/RCTEventDispatcher.h"
34
+#else
35
+  #import "RCTEventDispatcher.h"
32
 #endif
36
 #endif
33
 
37
 
34
 #import "RNPLocation.h"
38
 #import "RNPLocation.h"
59
 {
63
 {
60
     if (self = [super init]) {
64
     if (self = [super init]) {
61
     }
65
     }
62
-    
66
+
63
     return self;
67
     return self;
64
 }
68
 }
65
 
69
 
76
     resolve(@(UIApplicationOpenSettingsURLString != nil));
80
     resolve(@(UIApplicationOpenSettingsURLString != nil));
77
 }
81
 }
78
 
82
 
79
-    
83
+
80
 RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
84
 RCT_EXPORT_METHOD(openSettings:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
81
 {
85
 {
82
     if (@(UIApplicationOpenSettingsURLString != nil)) {
86
     if (@(UIApplicationOpenSettingsURLString != nil)) {
83
-        
87
+
84
         NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
88
         NSNotificationCenter * __weak center = [NSNotificationCenter defaultCenter];
85
         id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
89
         id __block token = [center addObserverForName:UIApplicationDidBecomeActiveNotification
86
                                                object:nil
90
                                                object:nil
89
                                                [center removeObserver:token];
93
                                                [center removeObserver:token];
90
                                                resolve(@YES);
94
                                                resolve(@YES);
91
                                            }];
95
                                            }];
92
-        
96
+
93
         NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
97
         NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
94
         [[UIApplication sharedApplication] openURL:url];
98
         [[UIApplication sharedApplication] openURL:url];
95
     }
99
     }
99
 RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
103
 RCT_REMAP_METHOD(getPermissionStatus, getPermissionStatus:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
100
 {
104
 {
101
     NSString *status;
105
     NSString *status;
102
-    
106
+
103
     switch (type) {
107
     switch (type) {
104
-            
108
+
105
         case RNPTypeLocation: {
109
         case RNPTypeLocation: {
106
             NSString *locationPermissionType = [RCTConvert NSString:json];
110
             NSString *locationPermissionType = [RCTConvert NSString:json];
107
             status = [RNPLocation getStatusForType:locationPermissionType];
111
             status = [RNPLocation getStatusForType:locationPermissionType];
147
 RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
151
 RCT_REMAP_METHOD(requestPermission, permissionType:(RNPType)type json:(id)json resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
148
 {
152
 {
149
     NSString *status;
153
     NSString *status;
150
-    
154
+
151
     switch (type) {
155
     switch (type) {
152
         case RNPTypeLocation:
156
         case RNPTypeLocation:
153
             return [self requestLocation:json resolve:resolve];
157
             return [self requestLocation:json resolve:resolve];
172
         default:
176
         default:
173
             break;
177
             break;
174
     }
178
     }
175
-    
179
+
176
 
180
 
177
 }
181
 }
178
 
182
 
181
     if (self.locationMgr == nil) {
185
     if (self.locationMgr == nil) {
182
         self.locationMgr = [[RNPLocation alloc] init];
186
         self.locationMgr = [[RNPLocation alloc] init];
183
     }
187
     }
184
-    
188
+
185
     NSString *type = [RCTConvert NSString:json];
189
     NSString *type = [RCTConvert NSString:json];
186
-    
190
+
187
     [self.locationMgr request:type completionHandler:resolve];
191
     [self.locationMgr request:type completionHandler:resolve];
188
 }
192
 }
189
 
193
 
190
 - (void) requestNotification:(id)json resolve:(RCTPromiseResolveBlock)resolve
194
 - (void) requestNotification:(id)json resolve:(RCTPromiseResolveBlock)resolve
191
 {
195
 {
192
     NSArray *typeStrings = [RCTConvert NSArray:json];
196
     NSArray *typeStrings = [RCTConvert NSArray:json];
193
-    
197
+
194
     UIUserNotificationType types;
198
     UIUserNotificationType types;
195
     if ([typeStrings containsObject:@"alert"])
199
     if ([typeStrings containsObject:@"alert"])
196
         types = types | UIUserNotificationTypeAlert;
200
         types = types | UIUserNotificationTypeAlert;
197
-    
201
+
198
     if ([typeStrings containsObject:@"badge"])
202
     if ([typeStrings containsObject:@"badge"])
199
         types = types | UIUserNotificationTypeBadge;
203
         types = types | UIUserNotificationTypeBadge;
200
-    
204
+
201
     if ([typeStrings containsObject:@"sound"])
205
     if ([typeStrings containsObject:@"sound"])
202
         types = types | UIUserNotificationTypeSound;
206
         types = types | UIUserNotificationTypeSound;
203
-    
204
-    
207
+
208
+
205
     if (self.notificationMgr == nil) {
209
     if (self.notificationMgr == nil) {
206
         self.notificationMgr = [[RNPNotification alloc] init];
210
         self.notificationMgr = [[RNPNotification alloc] init];
207
     }
211
     }
208
-    
212
+
209
     [self.notificationMgr request:types completionHandler:resolve];
213
     [self.notificationMgr request:types completionHandler:resolve];
210
 
214
 
211
 }
215
 }
216
     if (self.bluetoothMgr == nil) {
220
     if (self.bluetoothMgr == nil) {
217
         self.bluetoothMgr = [[RNPBluetooth alloc] init];
221
         self.bluetoothMgr = [[RNPBluetooth alloc] init];
218
     }
222
     }
219
-    
223
+
220
     [self.bluetoothMgr request:resolve];
224
     [self.bluetoothMgr request:resolve];
221
 }
225
 }
222
 
226