问题
I'm developing Bluetooth app.I have a name of available Bluetooth device in Table View..If press a device means i want to know all the supported services UUID name in another view controller with Table view.Give me an Idea.
1)Peripheralmanager (NSObject)
2)FirstViewController (In this I have a Device Name)
3)SecondViewController (In this I want Supported Services)
Peripheralmanager.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];
}
Tableview
-(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
{
}
If you want more information Please Ask me.
Please Check this Link sample Itunes app
image
回答1:
Well... First of all, you want Bluetooth Low Energy, which is quite different from the bluetooth. Even if the framework is called Bluetooth and the "normal one" is called ExternalAccessory. Right ?
I am not sure of what is really your question. Did you try the sample of Apple: CoreBluetooth Temperature Sensor ? Or even the two samples (temperature and heart monitor) works too since they uses the same framework. It will explain to you all it works : Peripheral > Service > Characteristic.
来源:https://stackoverflow.com/questions/13062096/how-to-display-the-supported-services-of-bluetooth-in-tableview-from-devicename