私はチップを持っており、LE Bluetooth で動作し、UUID を送信しています。IOS アプリからそれを発見し、UUID を取得する必要があります。2 つの IOS デバイス間の接続を確立する方法は知っていますが、別のチップとの接続は知りません。
ありがとう!
Apple のCoreBluetooth Temperature Exampleを確認してください。
まず、CBCentralManager を使用して、探している UUID を持つ利用可能な Bluetooth 周辺機器を見つけます。これはデリゲートを必要とする長いプロセスであり、これを行うためのコード スニペットを簡単に提供することはできません。このようになります。
.h file will have these. Remember to add the CoreBluetooth Framework.
#import <CoreBluetooth/CoreBluetooth.h>
CBCentralManager * manager;
CBPeripheral * connected_peripheral;
(それに応じて UUID を変更してください):
NSArray * services=[NSArray arrayWithObjects:
[CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"],
nil
];
[manager scanForPeripheralsWithServices:services options: [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]];
[manager connectPeripheral:peripheral options:nil];
そこから、適切な周辺機器があることがわかりますが、それでもそれを選択して、CBManager が新しいデバイスをスキャンし続けるのを停止する必要があります。
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
[manager stopScan];
NSArray *keys = [NSArray arrayWithObjects:
[CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"],
nil];
NSArray *objects = [NSArray arrayWithObjects:
@"My UUID to find",
nil];
serviceNames = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
[connected_peripheral setDelegate:self];
[connected_peripheral discoverServices:[serviceNames allKeys]];
}
ペリフェラルが持つサービスをアドバタイズするように周辺機器に指示したので、これらのサービスを解析するためのデリゲートができました。
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
CBService *bluetoothService;
for (bluetoothService in connected_peripheral.services) {
if([bluetoothService.UUID isEqual:[CBUUID UUIDWithString:@"0bd51666-e7cb-469b-8e4d-2742f1ba77cc"]])
{
NSLog(@"This is my bluetooth Service to Connect to");
}
}
このプロセスをもっと簡単に説明できればと思います。それを理解する最善の方法は、Apple の温度の例をダウンロードして、iPhone または iPad で実行することです (シミュレーターでは機能しません)。おそらく温度をブロードキャストしていない場合でも、Bluetooth LE デバイスを見つけて、ブロードキャストしているサービスを解析します。そのプロジェクトの LeDiscovery.m ファイルにブレークポイントを配置すると、iOS アプリから Bluetooth LE チップを検出するために必要な手順が表示されます。
お役に立てれば!