我正在开发蓝牙应用程序。我在 TableView 中有可用蓝牙设备的名称。如果按设备意味着我想知道另一个具有 TableView 的 View Controller 中支持的所有服务 UUID 名称。给我一个想法.
1)外设管理器(NSObject)
2)FirstViewController(在此我有一个设备名称)
3)SecondViewController(在此我想要支持的服务)
外设管理器.m
- (void)centralManager:(CBCentralManager *)central
didDiscoverPeripheral:(CBPeripheral *)peripheral
advertisementData:(NSDictionary *)advertisementData
RSSI:(NSNumber *)RSSI
{
NSLog(@"didDiscoverPeriphera.peripheral: %@ rssi: %@, UUID:%@ advertisementData:%@", peripheral,RSSI,peripheral.UUID, [advertisementData description]);
targetPeripheral = peripheral;
peripheral.delegate = self;
if (!peripheral.isConnected)
{
[centralManager connectPeripheral:peripheral options:nil];
}
}
FirstViewController.m
- (void)peripheralManagerDidConnectPeripheral:(PeripheralManager *)peripheral
{
NSLog(@"%@",peripheral.deviceName);
NSLog(@"%@",peripheral.rssi);
[device addObject:[NSString stringWithFormat:@"%@",peripheral.deviceName]];
[self.deviceTable reloadData];
}
表格 View
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier=@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if(cell==nil)
{
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text=[device objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
如果您想了解更多信息,请询问我。
请检查此链接 sample Itunes app
图像
最佳答案
嗯... 首先,您需要低功耗蓝牙,这与蓝牙有很大不同。即使框架称为蓝牙,而“普通框架”称为ExternalAccessory。 对吗?
我不确定你真正的问题是什么。 您尝试过Apple的 sample :CoreBluetooth温度传感器吗?或者甚至两个示例(温度和心脏监测器)也可以工作,因为它们使用相同的框架。 它将向您解释其所有工作原理:外围设备>服务>特征。
关于objective-c - 如何从devicename(UITableViewCell)中的tableview中显示蓝牙支持的服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062096/