Browse Source

Replace CBPeripheralManager.authorizationStatus (deprecated)

Mathieu Acthernoene 5 years ago
parent
commit
cb7c37634d
1 changed files with 23 additions and 12 deletions
  1. 23
    12
      ios/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m

+ 23
- 12
ios/BluetoothPeripheral/RNPermissionHandlerBluetoothPeripheral.m View File

32
     return resolve(RNPermissionStatusNotAvailable);
32
     return resolve(RNPermissionStatusNotAvailable);
33
   }
33
   }
34
 
34
 
35
-  switch ([CBPeripheralManager authorizationStatus]) {
36
-    case CBPeripheralManagerAuthorizationStatusNotDetermined:
37
-      return resolve(RNPermissionStatusNotDetermined);
38
-    case CBPeripheralManagerAuthorizationStatusRestricted:
39
-      return resolve(RNPermissionStatusRestricted);
40
-    case CBPeripheralManagerAuthorizationStatusDenied:
41
-      return resolve(RNPermissionStatusDenied);
42
-    case CBPeripheralManagerAuthorizationStatusAuthorized:
43
-      return resolve(RNPermissionStatusAuthorized);
35
+  if (@available(iOS 13.0, *)) {
36
+    switch ([[CBManager new] authorization]) {
37
+      case CBManagerAuthorizationNotDetermined:
38
+        return resolve(RNPermissionStatusNotDetermined);
39
+      case CBManagerAuthorizationRestricted:
40
+        return resolve(RNPermissionStatusRestricted);
41
+      case CBManagerAuthorizationDenied:
42
+        return resolve(RNPermissionStatusDenied);
43
+      case CBManagerAuthorizationAllowedAlways:
44
+        return resolve(RNPermissionStatusAuthorized);
45
+    }
46
+  } else {
47
+    switch ([CBPeripheralManager authorizationStatus]) {
48
+      case CBPeripheralManagerAuthorizationStatusNotDetermined:
49
+        return resolve(RNPermissionStatusNotDetermined);
50
+      case CBPeripheralManagerAuthorizationStatusRestricted:
51
+        return resolve(RNPermissionStatusRestricted);
52
+      case CBPeripheralManagerAuthorizationStatusDenied:
53
+        return resolve(RNPermissionStatusDenied);
54
+      case CBPeripheralManagerAuthorizationStatusAuthorized:
55
+        return resolve(RNPermissionStatusAuthorized);
56
+    }
44
   }
57
   }
45
 #endif
58
 #endif
46
 }
59
 }
62
 }
75
 }
63
 
76
 
64
 - (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
77
 - (void)peripheralManagerDidUpdateState:(nonnull CBPeripheralManager *)peripheral {
65
-  int state = peripheral.state;
66
-
67
   [_peripheralManager stopAdvertising];
78
   [_peripheralManager stopAdvertising];
68
   _peripheralManager = nil;
79
   _peripheralManager = nil;
69
 
80
 
70
-  switch (state) {
81
+  switch (peripheral.state) {
71
     case CBManagerStatePoweredOff:
82
     case CBManagerStatePoweredOff:
72
     case CBManagerStateResetting:
83
     case CBManagerStateResetting:
73
     case CBManagerStateUnsupported:
84
     case CBManagerStateUnsupported: