gpt4 book ai didi

ios - 将发现外围设备的UUID存储在CoreBluetooth LE iOS中

转载 作者:行者123 更新时间:2023-12-01 19:04:17 27 4
gpt4 key购买 nike

我尝试使用下面的代码将发现的设备的UUID存储到Array,然后在该阵列中选择UUID进行连接,但无法运行。

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

NSLog (@"Discovered peripheral: %@", [peripheral name]);
[foundArray addObject:peripheral.name];

NSLog (@"UUID peripheral: %@", [peripheral UUID]);

CFUUIDRef uuid = [peripheral UUID];
[discoverUUIDArray addObject: (__bridge id)(uuid)];
NSLog(@"Before = %@", uuid);

NSLog (@"peripheral services before connected: %@", [peripheral services]);

NSLog(@"adversting data %@",[NSString stringWithFormat:@"%@",[advertisementData description]]);

self.activePeripheral = peripheral;

NSLog(@"foundArray is %@", foundArray);
NSLog(@"discoverUUIDArray is %@", discoverUUIDArray);
[self.tblFound reloadData];

}

然后,我将这些Discover设备加载到tableview,当用户选择要连接的设备时,我的应用程序挂起。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.manager.state == CBCentralManagerStatePoweredOn)
{
NSLog(@"You selected %@ to connect",[foundArray objectAtIndex:indexPath.row]);
CFUUIDRef uuidGet = (__bridge CFUUIDRef) [discoverUUIDArray objectAtIndex:indexPath.row];
NSLog(@"UUID is %@",[discoverUUIDArray objectAtIndex:indexPath.row]);
[self.manager connectPeripheral:[discoverUUIDArray objectAtIndex:indexPath.row] options:nil];

}
}

选择要连接的设备时,显示错误:
[__NSCFType state]: unrecognized selector sent to instance 0x17d70950
2013-12-25 15:17:40.699 TestPeripheral[213:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType state]: unrecognized selector sent to instance 0x17d70950'

discoverUUIDArray存储发现设备的UUID。我不知道为什么请给我一些建议。非常感谢。

最佳答案

在iOS7中不推荐使用CFUUIDRef uuid = [peripheral UUID];
如果需要,可以使用peripheral.identifier作为NSUUID存储在数组中

如果要存储UUID's以便将来检索,请将其保留在NSUserDefaults中,而不是运行时数组中

关于ios - 将发现外围设备的UUID存储在CoreBluetooth LE iOS中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20770168/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com