Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if let bluetoothDevice = IOBluetoothDevice(addressString: "Bluetooth Device ID")
- {
- if !bluetoothDevice.isPaired() || !bluetoothDevice.isConnected() { continue }
- // Device is connected and paired, everything works fine until here.
- if bluetoothDevice.isHandsFreeDevice
- {
- // This line will also be executed, so the device supports the HFP.
- let handsFree = IOBluetoothHandsFree(device: bluetoothDevice, delegate: self)
- // handsFree?.connect()
- // Swift.print(handsFree?.isConnected) // returns false.
- let batteryValue = handsFree?.indicator(IOBluetoothHandsFreeIndicatorBattChg)
- Swift.print(batteryValue) // Always returns zero, can't be true.
- Swift.print(handsFree?.outputVolume) // Always returns 0.5.
- }
- }
- extension Controller : IOBluetoothHandsFreeDelegate
- {
- func handsFree(_ device: IOBluetoothHandsFree!, disconnected status: NSNumber!)
- {
- Swift.print("disconnected")
- }
- func handsFree(_ device: IOBluetoothHandsFree!, scoConnectionClosed status: NSNumber!)
- {
- Swift.print("scoConnectionClosed")
- }
- func handsFree(_ device: IOBluetoothHandsFree!, scoConnectionOpened status: NSNumber!)
- {
- Swift.print("scoConnectionOpened")
- }
- func handsFree(_ device: IOBluetoothHandsFree!, connected status: NSNumber!)
- {
- Swift.print("connected status: " + status.description)
- }
- func handsFree(_ device: IOBluetoothHandsFreeDevice!, batteryCharge: NSNumber!)
- {
- Swift.print("batteryCharge: " + batteryCharge.description)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement