iOS5.0で導入されたコアBluetoothフレームワークを試しています。StackOverflow自体の多くのスレッド(多くのスレッドの1つ)によると:
- コアBluetoothフレームワークは、Bluetooth Low Energy(4.0)ハードウェアをサポートする任意のハードウェアとの通信に使用できます。
- Core Bluetoothテクノロジを使用している場合は、Made For iPhone / iPod(MFI)プログラムを忘れることができます。
私はiPhone5、iPhone 4S、Google Android Nexus 7を持っており、少なくとも最初の2つはBLEのハードウェアサポートを備えていると確信しています。
私の質問は
さて、私は私のiPhone 4S / iPhone 5で以下のコードを試しましたが、スキャンして近くに座っているiPhone5 /iPhone4Sを見つけることができませんでした。確認できます。両方のデバイスでBluetoothがオンになっています。デリゲートメソッドdidDiscoverPeripheralが呼び出されることはありません。理由は何でしょうか?私は何かが足りないのですか?
これは私のコードです(小さなテストプロジェクトに分解されました)。
ViewController.h
@interface ViewController:UIViewController<CBCentralManagerDelegate, CBPeripheralDelegate{
}
@property (strong, nonatomic) CBCentralManager *mCentralManager;
@end
ViewController.m
@implementation ViewController
@synthesize mCentralManager;
- (void)viewDidLoad{
    [super viewDidLoad];
    mCentralManager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
    [self scanForPeripherals];
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    NSLog(@"Received periferal :%@",peripheral);
}
- (int) scanForPeripherals {
    if (self.mCentralManager.state != CBCentralManagerStatePoweredOn)
    {
        NSLog(@"self.mCentralManagerState : %d",self.mCentralManager.state);
        return -1;
    }
    //Getting here alright.. bluetooth is powered on.
    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
    //Documentation says passind nil as device UUID, scans and finds every peripherals
    [self.mCentralManager scanForPeripheralsWithServices:nil options:options];
    return 0;
}
@end