|
@@ -12,6 +12,14 @@
|
12
|
12
|
#import "RCTConvert.h"
|
13
|
13
|
#import "RCTEventDispatcher.h"
|
14
|
14
|
|
|
15
|
+#import "RCTConvert+RNPermissionsStatus.h"
|
|
16
|
+
|
|
17
|
+#import <AddressBook/AddressBook.h>
|
|
18
|
+#import <AssetsLibrary/AssetsLibrary.h>
|
|
19
|
+#import <EventKit/EventKit.h>
|
|
20
|
+#import <CoreLocation/CoreLocation.h>
|
|
21
|
+#import <AVFoundation/AVFoundation.h>
|
|
22
|
+#import <CoreBluetooth/CoreBluetooth.h>
|
15
|
23
|
|
16
|
24
|
@interface ReactNativePermissions()
|
17
|
25
|
@end
|
|
@@ -31,35 +39,181 @@ RCT_EXPORT_MODULE();
|
31
|
39
|
return self;
|
32
|
40
|
}
|
33
|
41
|
|
34
|
|
-RCT_REMAP_METHOD(start, start:(int)headingFilter resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
35
|
|
- // Start heading updates.
|
36
|
|
- if ([CLLocationManager headingAvailable]) {
|
37
|
|
- if (!headingFilter)
|
38
|
|
- headingFilter = 5;
|
39
|
|
-
|
40
|
|
- self.locManager.headingFilter = headingFilter;
|
41
|
|
- [self.locManager startUpdatingHeading];
|
42
|
|
- resolve(@YES);
|
43
|
|
- } else {
|
44
|
|
- resolve(@NO);
|
|
42
|
+- (NSDictionary *)constantsToExport
|
|
43
|
+{
|
|
44
|
+ return @{ @"StatusUndetermined" : @(RNPermissionsStatusUndetermined),
|
|
45
|
+ @"StatusDenied" : @(RNPermissionsStatusDenied),
|
|
46
|
+ @"StatusAuthorized" : @(RNPermissionsStatusAuthorized),
|
|
47
|
+ @"StatusRestricted" : @(RNPermissionsStatusRestricted)};
|
|
48
|
+};
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+RCT_REMAP_METHOD(locationPermissionStatus, locationPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
52
|
+{
|
|
53
|
+ int status = [CLLocationManager authorizationStatus];
|
|
54
|
+ switch (status) {
|
|
55
|
+ case kCLAuthorizationStatusAuthorizedAlways:
|
|
56
|
+ case kCLAuthorizationStatusAuthorizedWhenInUse:
|
|
57
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
58
|
+
|
|
59
|
+ case kCLAuthorizationStatusDenied:
|
|
60
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
61
|
+
|
|
62
|
+ case kCLAuthorizationStatusRestricted:
|
|
63
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
64
|
+
|
|
65
|
+ default:
|
|
66
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
67
|
+ }
|
|
68
|
+}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+RCT_REMAP_METHOD(cameraPermissionStatus, cameraPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
72
|
+{
|
|
73
|
+ int status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
74
|
+ switch (status) {
|
|
75
|
+ case AVAuthorizationStatusAuthorized:
|
|
76
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
77
|
+
|
|
78
|
+ case AVAuthorizationStatusDenied:
|
|
79
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
80
|
+
|
|
81
|
+ case AVAuthorizationStatusRestricted:
|
|
82
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
83
|
+
|
|
84
|
+ default:
|
|
85
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+RCT_REMAP_METHOD(microphonePermissionStatus, microphonePermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
91
|
+{
|
|
92
|
+ int status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
|
|
93
|
+ switch (status) {
|
|
94
|
+ case AVAuthorizationStatusAuthorized:
|
|
95
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
96
|
+
|
|
97
|
+ case AVAuthorizationStatusDenied:
|
|
98
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
99
|
+
|
|
100
|
+ case AVAuthorizationStatusRestricted:
|
|
101
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
102
|
+
|
|
103
|
+ default:
|
|
104
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
105
|
+ }
|
|
106
|
+
|
|
107
|
+}
|
|
108
|
+
|
|
109
|
+RCT_REMAP_METHOD(photoPermissionStatus, photoPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
110
|
+
|
|
111
|
+{
|
|
112
|
+ int status = [ALAssetsLibrary authorizationStatus];
|
|
113
|
+ switch (status) {
|
|
114
|
+ case ALAuthorizationStatusAuthorized:
|
|
115
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
116
|
+
|
|
117
|
+ case ALAuthorizationStatusDenied:
|
|
118
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
119
|
+
|
|
120
|
+ case ALAuthorizationStatusRestricted:
|
|
121
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
122
|
+
|
|
123
|
+ default:
|
|
124
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
45
|
125
|
}
|
46
|
126
|
}
|
47
|
127
|
|
48
|
|
-RCT_EXPORT_METHOD(stop) {
|
49
|
|
- [self.locManager stopUpdatingHeading];
|
|
128
|
+RCT_REMAP_METHOD(contactsPermissionStatus, contactsPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
129
|
+{
|
|
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));
|
|
143
|
+ }
|
50
|
144
|
}
|
51
|
145
|
|
52
|
|
-- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
|
53
|
|
- if (newHeading.headingAccuracy < 0)
|
54
|
|
- return;
|
|
146
|
+
|
|
147
|
+RCT_REMAP_METHOD(eventPermissionStatus, eventPermission:(NSString *)eventString resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
148
|
+{
|
|
149
|
+ int status;
|
|
150
|
+ if ([eventString isEqualToString:@"reminder"]) {
|
|
151
|
+ status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder];
|
|
152
|
+ } else if ([eventString isEqualToString:@"event"]) {
|
|
153
|
+ status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
|
|
154
|
+ } else {
|
|
155
|
+ NSError *error = [NSError errorWithDomain:@"invalidOption" code:-1 userInfo:NULL];
|
|
156
|
+ return reject(@"-1", @"Type must be 'reminder' or 'event'", error);
|
|
157
|
+ }
|
55
|
158
|
|
56
|
|
- // Use the true heading if it is valid.
|
57
|
|
- CLLocationDirection heading = ((newHeading.trueHeading > 0) ?
|
58
|
|
- newHeading.trueHeading : newHeading.magneticHeading);
|
|
159
|
+ switch (status) {
|
|
160
|
+ case EKAuthorizationStatusAuthorized:
|
|
161
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
162
|
+
|
|
163
|
+ case EKAuthorizationStatusDenied:
|
|
164
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
165
|
+
|
|
166
|
+ case EKAuthorizationStatusRestricted:
|
|
167
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
168
|
+
|
|
169
|
+ default:
|
|
170
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
171
|
+ }
|
|
172
|
+}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+RCT_REMAP_METHOD(bluetoothPermissionStatus, bluetoothPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
177
|
+{
|
|
178
|
+ int status = [CBPeripheralManager authorizationStatus];
|
59
|
179
|
|
60
|
|
- NSDictionary *headingEvent = @{@"heading": @(heading)};
|
|
180
|
+ switch (status) {
|
|
181
|
+ case CBPeripheralManagerAuthorizationStatusAuthorized:
|
|
182
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
183
|
+
|
|
184
|
+ case CBPeripheralManagerAuthorizationStatusDenied:
|
|
185
|
+ return resolve(@(RNPermissionsStatusDenied));
|
|
186
|
+
|
|
187
|
+ case CBPeripheralManagerAuthorizationStatusRestricted:
|
|
188
|
+ return resolve(@(RNPermissionsStatusRestricted));
|
|
189
|
+
|
|
190
|
+ default:
|
|
191
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
192
|
+ }
|
61
|
193
|
|
62
|
|
- [self.bridge.eventDispatcher sendDeviceEventWithName:@"headingUpdated" body:headingEvent];
|
63
|
194
|
}
|
64
|
195
|
|
|
196
|
+//problem here is that we can only return Authorized or Undetermined
|
|
197
|
+RCT_REMAP_METHOD(notificationPermissionStatus, notificationPermission:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
198
|
+{
|
|
199
|
+ if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
|
|
200
|
+ // iOS8+
|
|
201
|
+ if ([[UIApplication sharedApplication] isRegisteredForRemoteNotifications]) {
|
|
202
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
203
|
+ }
|
|
204
|
+ else {
|
|
205
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
206
|
+ }
|
|
207
|
+ } else {
|
|
208
|
+ if ([[UIApplication sharedApplication] enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
|
|
209
|
+ return resolve(@(RNPermissionsStatusUndetermined));
|
|
210
|
+ }
|
|
211
|
+ else {
|
|
212
|
+ return resolve(@(RNPermissionsStatusAuthorized));
|
|
213
|
+ }
|
|
214
|
+ }
|
|
215
|
+
|
|
216
|
+}
|
|
217
|
+
|
|
218
|
+
|
65
|
219
|
@end
|