現在、Bluetooth デバイスを使用できる iPhone アプリ (Xcode 4.3.1、IOS 5) を作成しています。このアプリケーションの主な目的は屋内ナビゲーションです (建物内の GPS はあまり正確ではありません)。
ここに表示される唯一の解決策 (アプリを AppStore に保持するため) は、利用可能な Bluetooth デバイスをスキャンすることです!
CoreBluetooth フレームワークを使用しようとしましたが、使用可能なデバイスのリストが表示されません! これらの機能を正しく使用していない可能性があります
#import <UIKit/UIKit.h>
#import <CoreBluetooth/CoreBluetooth.h>
@interface AboutBhyperView : UIViewController <CBPeripheralDelegate, CBCentralManagerDelegate>
{
CBCentralManager *mgr;
}
@property (readwrite, nonatomic) CBCentralManager *mgr;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
mgr = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
NSLog([NSString stringWithFormat:@"%@",[advertisementData description]]);
}
-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
NSLog(@"This is it!");
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSString *messtoshow;
switch (central.state) {
case CBCentralManagerStateUnknown:
{
messtoshow=[NSString stringWithFormat:@"State unknown, update imminent."];
break;
}
case CBCentralManagerStateResetting:
{
messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
break;
}
case CBCentralManagerStateUnsupported:
{
messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
break;
}
case CBCentralManagerStateUnauthorized:
{
messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
break;
}
case CBCentralManagerStatePoweredOff:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off."];
break;
}
case CBCentralManagerStatePoweredOn:
{
messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered on and available to use."];
[mgr scanForPeripheralsWithServices:nil options:nil];
//[mgr retrieveConnectedPeripherals];
//--- it works, I Do get in this area!
break;
}
}
NSLog(messtoshow);
}
この行についてよくわかりません。正しいパラメータを渡す方法を教えてください。
[mgr scanForPeripheralsWithServices:nil options:nil];
私はアップルのリファレンスを調べました..そして私はまだそのCBUUIDが何であるかを理解していません??? すべてのデバイスには Bluetooth ID がありますか? どこで見つけることができますか?
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options;
パラメーター serviceUUIDs - アプリが対象とする CBUUID の配列。 options - スキャンをカスタマイズするための辞書。CBCentralManagerScanOptionAllowDuplicatesKey を参照してください。
IOS で Bluetooth を使用する他の方法はありますか? つまり、BLE 4.0 を使用しない古いフレームワークです。
アドバイスをいただければ幸いです。
ありがとう!