【发布时间】:2015-01-01 14:53:36
【问题描述】:
我正在开发一个使用 CoreBluetooth 框架的应用程序 IOS 应用程序,我正在尝试从“didDiscoverPheripheral”方法的 CBPeripheral 对象中获取手机的名称并将其添加到数组中,以便可以在 tableView 上显示它。我的意思是“电话名称”类似于“Dan 的 iPhone”。 稍后我想按下 tableView 上的行,以便连接到该设备。
我试过了:
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);
if (_discoveredPeripheral != peripheral) {
// Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it
_discoveredPeripheral = peripheral;
// And connect
NSLog(@"Connecting to peripheral %@", peripheral);
// here i want to add the name of the device to an array
}
}
有什么想法吗??
【问题讨论】:
-
NSLog(@"设备名称: %@", [[UIDevice currentDevice] name]);
-
运行这段代码会发生什么?
标签: ios bluetooth core-bluetooth