Ios CoreBluetooth.name始终为零
我只想知道附近蓝牙设备的名称。但是,peripheral.name始终为零。广告包装中的名称也始终为零。我在附近有7台设备。我能看见他们,但看不到他们的名字 我正在使用Swift2.0和XCode7 我的代码如下,我还添加了corebooth.framework:Ios CoreBluetooth.name始终为零,ios,swift,bluetooth,swift2,core-bluetooth,Ios,Swift,Bluetooth,Swift2,Core Bluetooth,我只想知道附近蓝牙设备的名称。但是,peripheral.name始终为零。广告包装中的名称也始终为零。我在附近有7台设备。我能看见他们,但看不到他们的名字 我正在使用Swift2.0和XCode7 我的代码如下,我还添加了corebooth.framework: import UIKit import CoreBluetooth class ViewController: UIViewController, CBCentralManagerDelegate { var centra
import UIKit
import CoreBluetooth
class ViewController: UIViewController, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
var blueToothReady = false
override func viewDidLoad() {
super.viewDidLoad()
startUpCentralManager()
}
func startUpCentralManager() {
print("Initializing central manager")
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func discoverDevices() {
print("discovering devices")
centralManager.scanForPeripheralsWithServices(nil, options: nil)
// centralManager.scanForPeripheralsWithServices(nil, options: [CBCentralManagerScanOptionAllowDuplicatesKey : NSNumber(bool: true)])
}
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
let nameOfDeviceFound = (advertisementData as NSDictionary).objectForKey(CBAdvertisementDataLocalNameKey) as? NSString
print("\(nameOfDeviceFound)")
print("Discovered \(peripheral.name)")
}
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) {
print("Connected to a peripheral")
}
func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) {
print("Failed to connect to peripheral")
}
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
print("Disconnected from Peripheral")
}
func centralManager(central: CBCentralManager, willRestoreState dict: [String : AnyObject]) {
print("Will restore state")
}
func centralManagerDidUpdateState(central: CBCentralManager) {
print("checking state")
switch (central.state) {
case .PoweredOff:
print("CoreBluetooth BLE hardware is powered off")
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()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
提前谢谢 你能在iPhone蓝牙设置中看到同一设备的名称吗?该名称是否显示在像LightBlue这样的蓝牙低能量嗅探器中?你在用什么样的设备进行测试?谢谢你的评论。我可以在iPhone蓝牙设置中看到姓名。我看不到LightBlue中的名称。顺便说一句:我附近有蓝牙扬声器、其他iPhone、iPad等蓝牙设备。