objective-c - 如何从devicename(UITableViewCell)中的tableview中显示蓝牙支持的服务?

标签 objective-c ios uitableview ios5 core-bluetooth

我正在开发蓝牙应用程序。我在 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

图像 enter image description here

enter image description here

最佳答案

嗯... 首先,您需要低功耗蓝牙,这与蓝牙有很大不同。即使框架称为蓝牙,而“普通框架”称为ExternalAccessory。 对吗?

我不确定你真正的问题是什么。 您尝试过Apple的 sample :CoreBluetooth温度传感器吗?或者甚至两个示例(温度和心脏监测器)也可以工作,因为它们使用相同的框架。 它将向您解释其所有工作原理:外围设备>服务>特征。

关于objective-c - 如何从devicename(UITableViewCell)中的tableview中显示蓝牙支持的服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13062096/

相关文章:

ios - Objective-C 中的参数类型 (void *) 如何转换为 Swift 中的 UnsafePointer<()> ?

ios - 动态添加 UIActionSheet 按钮时如何对它们进行分组

ios - 在 UITableViewCell 中嵌套 UITextField 的问题

objective-c - 如何在 drawRect 中为 NSTextField 或 NSTextVew 实现自定义聚焦环

iphone - 在 UILabel 中使用带有粗体文本的自定义字体

ios - iOS座位计划布局

objective-c - 从自定义 uitableviewcell 中的按钮点击委托(delegate)

ios - 如何将高度设置为从 xib 加载的 tableFooterView

iphone - 标签标签 0 的奇怪问题?

objective-c - 如何在 NSBrowser 中突出显示一行?