Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取电话';来自CBPheriPeral IOS的s名称_Ios_Bluetooth_Core Bluetooth - Fatal编程技术网

获取电话';来自CBPheriPeral IOS的s名称

获取电话';来自CBPheriPeral IOS的s名称,ios,bluetooth,core-bluetooth,Ios,Bluetooth,Core Bluetooth,我正在开发一款应用程序,IOS应用程序使用CoreBluetooth框架,我正在尝试通过“DidDiscoveryPheripheral”方法从CBPeripheral对象获取手机名称,并将其添加到一个数组中,以便在tableView上显示。我的意思是“手机名”类似于“丹的iPhone”。 稍后,我想按tableView上的行,以便连接到该设备 我试过: - (void)centralManager:(CBCentralManager *)central didDiscoverPeripher

我正在开发一款应用程序,IOS应用程序使用CoreBluetooth框架,我正在尝试通过“DidDiscoveryPheripheral”方法从CBPeripheral对象获取手机名称,并将其添加到一个数组中,以便在tableView上显示。我的意思是“手机名”类似于“丹的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
}
}

有什么想法吗???

在发现并创建Bluetooth类中的另一个方法并调用该方法从TableView连接到所选设备后,为什么不添加外围设备:

 - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral    *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {

     NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);
      // add found devices to class variable NSMutableArray<CBPeripheral> *foundPeripherals
     // do not forget to initialize it
     [self.foundPeripherals addObject:peripheral];

}

// create a connect method where you pass the device selected identifier
- (void) connect:(NSString*)uuidString {
    CBPeripheral* peripheral;
    for (peripheral in self.foundPeripherals){
        if(peripheral.state == CBPeripheralStateDisconnected){
            // this will invoke didConnectPeripheral once connection 
            // set successfully
            [self connectPeripheral:peripheral];
        }
    }
}

// store the connected peripheral
- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:     (CBPeripheral *)peripheral
{
    NSLog(@"Attempted connection to peripheral %@ succeed.", [peripheral name]);
    // store the connected device info in class property
    self.peripheral = peripheral;
}
-(无效)中央管理器:(CBCentralManager*)中央发现外围设备:(CBPeripheral*)外围广告数据:(NSDictionary*)广告数据RSSI:(NSNumber*)RSSI{
NSLog(@“发现%@在%@”,peripheral.name,RSSI);
//将找到的设备添加到类变量NSMutableArray*foundPeripherals
//别忘了初始化它
[self.foundPeripherals addObject:peripheral];
}
//创建一个连接方法,在其中传递所选设备标识符
-(void)connect:(NSString*)uuistring{
CBP外围设备*外围设备;
用于(self.foundPeripherals中的外围设备){
if(peripheral.state==CBPeripheralStateDisconnected){
//这将调用didConnectPeripheral once连接
//设置成功
[自连接外围设备:外围设备];
}
}
}
//存储连接的外围设备
-(无效)中央管理器:(CBCentralManager*)中央数据连接外围设备:(CBPeripheral*)外围设备
{
NSLog(@“尝试连接到外围设备%@成功”。,[外围设备名称];
//在类属性中存储连接的设备信息
self.peripheral=外围设备;
}

NSLog(@“设备名称:%@,[[UIDevice currentDevice]名称]);运行此代码时会发生什么情况?