I am currently implementing the bluetooth permission on my application. I use CBManager.authorization
to get the current state of the authorization but it is only for ios 13.1. This is an open var class authorization
and there is another one as a var authorization
. I cannot call any of them for iOS 13 or below versions. It makes sense because there is no bluetooth permission for iOS 12. There is one for ios 13.0 but it cannot be called which is strange. I really need a good practice to check the status of the permission.
Asked
Active
Viewed 539 times
-1

jorjj
- 1,479
- 4
- 20
- 36
-
You can use the deprecated `authorization` instance property on iOS 13.0 and the class car on iOS 13.1+ + use a `#available` check – Paulw11 Nov 29 '19 at 21:06
1 Answers
0
You should use CBCentralManage
. Create an instance:
let manager = CBCentralManage(delegate: self, queue: nil, options: nil)
and use the delegate like:
func centralManagerDidUpdateState(_ central: CBCentralManager) {
switch central.state {
case .unknown: <#code#>
case .resetting: <#code#>
case .unsupported: <#code#>
case .unauthorized: <#code#>
case .poweredOff: <#code#>
case .poweredOn: <#code#>
@unknown default: <#code#>
}
}
Assuming you didn't forget to update .plist
file for permission messages

Mojtaba Hosseini
- 95,414
- 31
- 268
- 278
-
I already use this method. The thing is, I work on the latest iOS version so I didn't really test if it works for iOS 13. So does this work before allocating the CBCentralManager? Because that is what I want and the new method works well for the latest iOS versions. You can actually use central.authorization for ios 13 in the centralManagerDidUpdateState method btw. – jorjj Nov 29 '19 at 19:52