3

I am trying to list all the bluetooth connected audio devices. But there is no log in delegate functions. Also tried the solution from Switching audio output between Receiver and Speaker in iOS7 and above?

Following is my code...

import UIKit
import CoreBluetooth
import AVFoundation

class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralManagerDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

    do{
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.AllowBluetooth)
    } catch{
        print(error)
    }

    let manager = CBCentralManager.init(delegate: self, queue: nil)
    manager.scanForPeripheralsWithServices(nil, options: nil)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

func centralManagerDidUpdateState(central: CBCentralManager) {
    print(central.state)
}

func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
    print(peripheral)
}

func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) {
    print(peripheral)
}

}

In my case, there is an audio player and a button(like the default airplay button in music). On clicking the button, it should display all the connected bluetooth devices. Is it possible to list all the devices? Also I cannot use Apple's MKVolumeView because I have to further create a cordova plugin.

Community
  • 1
  • 1
Tanisha
  • 41
  • 1
  • 1
  • 5
  • There is Objective-C solution at http://stackoverflow.com/a/20898939/1459192. Hope you can easily convert. – x4h1d Sep 19 '16 at 13:48
  • And also this one here: http://stackoverflow.com/questions/30636637/possible-to-generate-a-list-of-connected-bluetooth-devices-for-ios – tech4242 Sep 19 '16 at 14:01
  • 1
    Audio is not suited for Bluetooth Low-Energy, and CoreBluetooth is ONLY for Bluetooth Low-Energy. Check with `AVAudioSession`. – Larme Sep 19 '16 at 14:14
  • 1
    @tech4242 Thanx for the reply. Though my problem is still not solved. I had already tried the solutions given in links you gave . Also, I have edited my question to be bit more specific. – Tanisha Sep 20 '16 at 07:25
  • @Larme Thanx for the reply. Though my problem is still not solved. Also, I have edited my question to be bit more specific. – Tanisha Sep 20 '16 at 07:44

0 Answers0