Selaa lähdekoodia

Fix Bluetooth permission

Mathieu Acthernoene 6 vuotta sitten
vanhempi
commit
a4e415e5d9

+ 1
- 1
index.js Näytä tiedosto

22
 // }
22
 // }
23
 
23
 
24
 export const IOS_PERMISSIONS = {
24
 export const IOS_PERMISSIONS = {
25
-  BLUETOOTH_PERIPHERICAL: "BLUETOOTH_PERIPHERICAL",
25
+  BLUETOOTH_PERIPHERAL: "BLUETOOTH_PERIPHERAL",
26
   CALENDARS: "CALENDARS",
26
   CALENDARS: "CALENDARS",
27
   CAMERA: "CAMERA",
27
   CAMERA: "CAMERA",
28
   CONTACTS: "CONTACTS",
28
   CONTACTS: "CONTACTS",

+ 18
- 6
ios/PermissionHandlers/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m Näytä tiedosto

12
 
12
 
13
 @implementation RNPermissionHandlerBluetoothPeripheral
13
 @implementation RNPermissionHandlerBluetoothPeripheral
14
 
14
 
15
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
16
-  return [RNPermissionsManager hasBackgroundModeEnabled:@"bluetooth-peripheral"] ? @[@"NSBluetoothPeripheralUsageDescription"] : nil;
15
++ (NSArray<NSString *> *)usageDescriptionKeys {
16
+  return @[@"NSBluetoothPeripheralUsageDescription"];
17
 }
17
 }
18
 
18
 
19
 - (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
19
 - (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
20
              withRejecter:(void (__unused ^)(NSError *error))reject {
20
              withRejecter:(void (__unused ^)(NSError *error))reject {
21
+#if TARGET_OS_SIMULATOR
22
+  return resolve(RNPermissionStatusNotAvailable);
23
+#else
24
+  if (![RNPermissionsManager hasBackgroundModeEnabled:@"bluetooth-peripheral"]) {
25
+    return resolve(RNPermissionStatusNotAvailable);
26
+  }
27
+
21
   switch ([CBPeripheralManager authorizationStatus]) {
28
   switch ([CBPeripheralManager authorizationStatus]) {
22
     case CBPeripheralManagerAuthorizationStatusNotDetermined:
29
     case CBPeripheralManagerAuthorizationStatusNotDetermined:
23
       return resolve(RNPermissionStatusNotDetermined);
30
       return resolve(RNPermissionStatusNotDetermined);
28
     case CBPeripheralManagerAuthorizationStatusAuthorized:
35
     case CBPeripheralManagerAuthorizationStatusAuthorized:
29
       return resolve(RNPermissionStatusAuthorized);
36
       return resolve(RNPermissionStatusAuthorized);
30
   }
37
   }
38
+#endif
31
 }
39
 }
32
 
40
 
33
 - (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
41
 - (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
34
               withResolver:(void (^)(RNPermissionStatus status))resolve
42
               withResolver:(void (^)(RNPermissionStatus status))resolve
35
               withRejecter:(void (^)(NSError *error))reject {
43
               withRejecter:(void (^)(NSError *error))reject {
44
+  if (![RNPermissionsManager hasBackgroundModeEnabled:@"bluetooth-peripheral"]) {
45
+    return resolve(RNPermissionStatusNotAvailable);
46
+  }
47
+
36
   _resolve = resolve;
48
   _resolve = resolve;
37
   _reject = reject;
49
   _reject = reject;
38
-  
50
+
39
   _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:@{
51
   _peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:@{
40
     CBPeripheralManagerOptionShowPowerAlertKey: @false,
52
     CBPeripheralManagerOptionShowPowerAlertKey: @false,
41
   }];
53
   }];
42
-  
54
+
43
   [_peripheralManager startAdvertising:@{}];
55
   [_peripheralManager startAdvertising:@{}];
44
 }
56
 }
45
 
57
 
46
 - (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
58
 - (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
47
   CBManagerState state = peripheral.state;
59
   CBManagerState state = peripheral.state;
48
-  
60
+
49
   [_peripheralManager stopAdvertising];
61
   [_peripheralManager stopAdvertising];
50
   _peripheralManager = nil;
62
   _peripheralManager = nil;
51
-  
63
+
52
   switch (state) {
64
   switch (state) {
53
     case CBManagerStatePoweredOn:
65
     case CBManagerStatePoweredOn:
54
       return [self checkWithResolver:_resolve withRejecter:_reject];
66
       return [self checkWithResolver:_resolve withRejecter:_reject];

+ 1
- 1
ios/PermissionHandlers/Calendars/RNPermissionHandlerCalendars.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerCalendars
5
 @implementation RNPermissionHandlerCalendars
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSCalendarsUsageDescription"];
8
   return @[@"NSCalendarsUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Camera/RNPermissionHandlerCamera.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerCamera
5
 @implementation RNPermissionHandlerCamera
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSCameraUsageDescription"];
8
   return @[@"NSCameraUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Contacts/RNPermissionHandlerContacts.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerContacts
5
 @implementation RNPermissionHandlerContacts
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSContactsUsageDescription"];
8
   return @[@"NSContactsUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 4
- 4
ios/PermissionHandlers/FaceID/RNPermissionHandlerFaceID.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerFaceID
5
 @implementation RNPermissionHandlerFaceID
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSFaceIDUsageDescription"];
8
   return @[@"NSFaceIDUsageDescription"];
9
 }
9
 }
10
 
10
 
60
       return resolve(RNPermissionStatusAuthorized);
60
       return resolve(RNPermissionStatusAuthorized);
61
     }
61
     }
62
 
62
 
63
-    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSFaceIDUsageDescription"] reply:^(BOOL success, NSError * _Nullable evaluationError) {
64
-      if (evaluationError != nil) {
65
-        [self handleError:evaluationError withResolver:resolve withRejecter:reject];
63
+    [context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSFaceIDUsageDescription"] reply:^(BOOL success, NSError * _Nullable error) {
64
+      if (error != nil) {
65
+        [self handleError:error withResolver:resolve withRejecter:reject];
66
       } else {
66
       } else {
67
         resolve(success ? RNPermissionStatusAuthorized : RNPermissionStatusDenied);
67
         resolve(success ? RNPermissionStatusAuthorized : RNPermissionStatusDenied);
68
       }
68
       }

+ 1
- 1
ios/PermissionHandlers/LocationAlways/RNPermissionHandlerLocationAlways.m Näytä tiedosto

14
 
14
 
15
 @implementation RNPermissionHandlerLocationAlways
15
 @implementation RNPermissionHandlerLocationAlways
16
 
16
 
17
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
17
++ (NSArray<NSString *> *)usageDescriptionKeys {
18
   return @[
18
   return @[
19
     @"NSLocationAlwaysAndWhenInUseUsageDescription",
19
     @"NSLocationAlwaysAndWhenInUseUsageDescription",
20
     @"NSLocationAlwaysUsageDescription",
20
     @"NSLocationAlwaysUsageDescription",

+ 1
- 1
ios/PermissionHandlers/LocationWhenInUse/RNPermissionHandlerLocationWhenInUse.m Näytä tiedosto

13
 
13
 
14
 @implementation RNPermissionHandlerLocationWhenInUse
14
 @implementation RNPermissionHandlerLocationWhenInUse
15
 
15
 
16
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
16
++ (NSArray<NSString *> *)usageDescriptionKeys {
17
   return @[@"NSLocationWhenInUseUsageDescription"];
17
   return @[@"NSLocationWhenInUseUsageDescription"];
18
 }
18
 }
19
 
19
 

+ 1
- 1
ios/PermissionHandlers/MediaLibrary/RNPermissionHandlerMediaLibrary.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerMediaLibrary
5
 @implementation RNPermissionHandlerMediaLibrary
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSAppleMusicUsageDescription"];
8
   return @[@"NSAppleMusicUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Microphone/RNPermissionHandlerMicrophone.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerMicrophone
5
 @implementation RNPermissionHandlerMicrophone
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSMicrophoneUsageDescription"];
8
   return @[@"NSMicrophoneUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Motion/RNPermissionHandlerMotion.m Näytä tiedosto

13
 
13
 
14
 @implementation RNPermissionHandlerMotion
14
 @implementation RNPermissionHandlerMotion
15
 
15
 
16
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
16
++ (NSArray<NSString *> *)usageDescriptionKeys {
17
   return @[@"NSMotionUsageDescription"];
17
   return @[@"NSMotionUsageDescription"];
18
 }
18
 }
19
 
19
 

+ 1
- 1
ios/PermissionHandlers/PhotoLibrary/RNPermissionHandlerPhotoLibrary.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerPhotoLibrary
5
 @implementation RNPermissionHandlerPhotoLibrary
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSPhotoLibraryUsageDescription"];
8
   return @[@"NSPhotoLibraryUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Reminders/RNPermissionHandlerReminders.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerReminders
5
 @implementation RNPermissionHandlerReminders
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSRemindersUsageDescription"];
8
   return @[@"NSRemindersUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/Siri/RNPermissionHandlerSiri.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerSiri
5
 @implementation RNPermissionHandlerSiri
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSSiriUsageDescription"];
8
   return @[@"NSSiriUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/PermissionHandlers/SpeechRecognition/RNPermissionHandlerSpeechRecognition.m Näytä tiedosto

4
 
4
 
5
 @implementation RNPermissionHandlerSpeechRecognition
5
 @implementation RNPermissionHandlerSpeechRecognition
6
 
6
 
7
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys {
7
++ (NSArray<NSString *> *)usageDescriptionKeys {
8
   return @[@"NSSpeechRecognitionUsageDescription"];
8
   return @[@"NSSpeechRecognitionUsageDescription"];
9
 }
9
 }
10
 
10
 

+ 1
- 1
ios/RCTConvert+RNPermission.m Näytä tiedosto

4
 
4
 
5
 RCT_ENUM_CONVERTER(RNPermission, (@{
5
 RCT_ENUM_CONVERTER(RNPermission, (@{
6
 #if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
6
 #if __has_include("RNPermissionHandlerBluetoothPeripheral.h")
7
-  @"BLUETOOTH_PERIPHERICAL": @(RNPermissionBluetoothPeripheral),
7
+  @"BLUETOOTH_PERIPHERAL": @(RNPermissionBluetoothPeripheral),
8
 #endif
8
 #endif
9
 #if __has_include("RNPermissionHandlerCalendars.h")
9
 #if __has_include("RNPermissionHandlerCalendars.h")
10
   @"CALENDARS": @(RNPermissionCalendars),
10
   @"CALENDARS": @(RNPermissionCalendars),

+ 1
- 1
ios/RNPermissionsManager.h Näytä tiedosto

12
 
12
 
13
 @optional
13
 @optional
14
 
14
 
15
-+ (NSArray<NSString *> * _Nullable)usageDescriptionKeys;
15
++ (NSArray<NSString *> *)usageDescriptionKeys;
16
 
16
 
17
 @required
17
 @required
18
 
18
 

+ 4
- 6
ios/RNPermissionsManager.m Näytä tiedosto

158
   if (handler != nil && [[handler class] respondsToSelector:@selector(usageDescriptionKeys)]) {
158
   if (handler != nil && [[handler class] respondsToSelector:@selector(usageDescriptionKeys)]) {
159
     NSArray<NSString *> *usageDescriptionKeys = [[handler class] usageDescriptionKeys];
159
     NSArray<NSString *> *usageDescriptionKeys = [[handler class] usageDescriptionKeys];
160
 
160
 
161
-    if (usageDescriptionKeys != nil) {
162
-      for (NSString *key in usageDescriptionKeys) {
163
-        if (![[NSBundle mainBundle] objectForInfoDictionaryKey:key]) {
164
-          RCTLogError(@"Cannot check or request permission without the required \"%@\" entry in your app \"Info.plist\" file.", key);
165
-          return nil;
166
-        }
161
+    for (NSString *key in usageDescriptionKeys) {
162
+      if (![[NSBundle mainBundle] objectForInfoDictionaryKey:key]) {
163
+        RCTLogError(@"Cannot check or request permission without the required \"%@\" entry in your app \"Info.plist\" file.", key);
164
+        return nil;
167
       }
165
       }
168
     }
166
     }
169
   }
167
   }