Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.61 KB | None | 0 0
  1. if let bluetoothDevice = IOBluetoothDevice(addressString: "Bluetooth Device ID")
  2. {
  3.     if !bluetoothDevice.isPaired() || !bluetoothDevice.isConnected() { continue }                    
  4.     // Device is connected and paired, everything works fine until here.
  5.     if bluetoothDevice.isHandsFreeDevice
  6.     {
  7.        // This line will also be executed, so the device supports the HFP.
  8.        let handsFree = IOBluetoothHandsFree(device: bluetoothDevice, delegate: self)
  9.        // handsFree?.connect()
  10.        // Swift.print(handsFree?.isConnected) // returns false.
  11.        let batteryValue = handsFree?.indicator(IOBluetoothHandsFreeIndicatorBattChg)
  12.        Swift.print(batteryValue) // Always returns zero, can't be true.
  13.        Swift.print(handsFree?.outputVolume) // Always returns 0.5.
  14.     }
  15. }
  16.  
  17. extension Controller : IOBluetoothHandsFreeDelegate
  18. {
  19.     func handsFree(_ device: IOBluetoothHandsFree!, disconnected status: NSNumber!)
  20.     {
  21.         Swift.print("disconnected")
  22.     }
  23.    
  24.     func handsFree(_ device: IOBluetoothHandsFree!, scoConnectionClosed status: NSNumber!)
  25.     {
  26.         Swift.print("scoConnectionClosed")
  27.     }
  28.    
  29.     func handsFree(_ device: IOBluetoothHandsFree!, scoConnectionOpened status: NSNumber!)
  30.     {
  31.         Swift.print("scoConnectionOpened")
  32.     }
  33.    
  34.     func handsFree(_ device: IOBluetoothHandsFree!, connected status: NSNumber!)
  35.     {
  36.         Swift.print("connected status: " + status.description)
  37.     }
  38.    
  39.     func handsFree(_ device: IOBluetoothHandsFreeDevice!, batteryCharge: NSNumber!)
  40.     {
  41.         Swift.print("batteryCharge: " + batteryCharge.description)
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement