我正在实施一个使用蓝牙连接到Raspberry Pi的OS X应用程序。 问题是应用程序无法发现RPI,而我可以在Mac的本机蓝牙面板上看到它。 该应用程序仅发现一个具有" null"名称(我在Mac的蓝牙面板上看到的每个设备都有一个名字)。
对问题可能是什么有任何想法?
以下是我的蓝牙管理器单例的实现:
static let sharedInstance = KNKBluetoothManager()
var centralManager : CBCentralManager!
var remotePeripheral : CBPeripheral?
var bluetoothReady = false
func startUpCentralManager()
{
print("Initializing central manager")
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func discoverDevices()
{
print("discovering devices")
centralManager.scanForPeripheralsWithServices(nil, options: nil)
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)
{
print("Discovered \(peripheral)")
if (peripheral.name == "rpi")
{
self.remotePeripheral = peripheral
self.centralManager.stopScan()
self.remotePeripheral?.delegate = self
centralManager.connectPeripheral(peripheral, options: nil)
}
}
func centralManagerDidUpdateState(central: CBCentralManager)
{
print("checking state")
switch (central.state)
{
case .PoweredOff:
print("CoreBluetooth BLE hardware is powered off")
bluetoothReady = false
case .PoweredOn:
print("CoreBluetooth BLE hardware is powered on and ready")
bluetoothReady = true;
case .Resetting:
print("CoreBluetooth BLE hardware is resetting")
case .Unauthorized:
print("CoreBluetooth BLE state is unauthorized")
case .Unknown:
print("CoreBluetooth BLE state is unknown");
case .Unsupported:
print("CoreBluetooth BLE hardware is unsupported on this platform");
}
if bluetoothReady
{
discoverDevices()
}
}
didDiscoverPeripheral
方法总是找到相同的外围设备:
Discovered <CBPeripheral: 0x6080000aada0 identifier = 36844111-01E4-4D00-926B-AAF089C04305, Name = "(null)", state = disconnected>
很好地指出我在iOS应用程序(使用iPhone 5)上使用相同的实现时遇到了完全相同的问题。