核心蓝牙框架不扫描所有BLE设备和苹果BLE设备

时间:2014-10-07 06:13:26

标签: ios swift core-bluetooth

我正在使用Core蓝牙框架并扫描一些设备,如micromax A250,micromax A116,samsung grand neo,HTC 610和ipod 5s然后我无法扫描三星,HTC和ipod可能是什么原因?请帮我提前解决。

// object creation



@IBAction func btnScanClicked(sender:UIButton)
    {

        var centralManager:CBCentralManager = CBCentralManager(delegate: self, queue: nil)
        self.centralManager = centralManager
    }

 //   method called whenever the device state changes.

func centralManagerDidUpdateState(central: CBCentralManager!) {

        if central.state == CBCentralManagerState.PoweredOff
        {
            println("bluetooth is off")
        }
        else if central.state == CBCentralManagerState.PoweredOn
        {
            central.scanForPeripheralsWithServices(nil, options: nil) // scanning devices
            println("bluetooth is on")

        }
        else if central.state == CBCentralManagerState.Unknown
        {
            println("bluetooth is unknown")
        }
        else if central.state == CBCentralManagerState.Unsupported
        {
            println("bluetooth is unsupported")
        }
    }

// method to discover peripherals:- 

func centralManager(central: CBCentralManager!, didDiscoverPeripheral peripheral: CBPeripheral!, advertisementData: [NSObject : AnyObject]!, RSSI: NSNumber!)

    {
        if peripheral != nil{
                println("discovered \(peripheral.name)")
        }
        else
        {
            println("No device found")
        }
        self.peripheral = peripheral
        peripheral.delegate = self
        central!.connectPeripheral(peripheral, options: nil)
    }

// method to connect:-

func centralManager(central: CBCentralManager!, didConnectPeripheral peripheral: CBPeripheral!)

    {
        peripheral.delegate = self
        peripheral.discoverServices(nil)
        if ((peripheral) != nil)
        {
            var state = peripheral.state == CBPeripheralState.Connected ? "yes" : "no"
            connected = "Connected \(state)"
            println("connected \(connected)")
        }
    }

1 个答案:

答案 0 :(得分:0)

Android操作系统不支持将手机用作外围设备,仅支持将其用作主设备。

除非正在运行软件,否则iPhone不会像外围设备那样运行。您可以在其开发人员门户网站上提供的Apple的BTLE_Transfer示例应用程序中找到iOS设备广告的示例代码作为外围设备。