1

iPhone アプリを実行していますが、近くの Bluetooth デバイスを取得する必要があります。CoreBluetooth フレームワークを使用していますが、機能しません。このフレームワークが Low Energy Bluetooth 専用であることはわかっているので、Low-Energy をサポートする Bluetooth 4.0 USB アダプターを購入しました。iPhone 5 でこのアプリをテストしています。これが私のコードです

- (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:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"180A"]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]];

        [mgr retrieveConnectedPeripherals];


        break;
    }               
}
NSLog(messtoshow); 
}   

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:
(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSLog(@"Did discover peripheral. peripheral: %@ rssi: %@, UUID: %@ advertisementData: %@ ", peripheral, RSSI, peripheral.UUID, advertisementData);
[mgr retrievePeripherals:[NSArray arrayWithObject:(id)peripheral.UUID]];
}

-(void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals{
NSLog(@"This is it!");
}

この出力は「Bluetooth は現在電源が入っており、使用可能です。」と表示されますが、USB Bluetooth または近くにある他の Bluetooth デバイスが見つかりません。私はこれに対する解決策が必要です、私は夢中になっています。どうもありがとうございました。

4

2 に答える 2

0

あなたのコードは問題ないようです。 アプリ ストアで TI BLE を検索して、無料の iPhone アプリを入手してください。

アプリが Bluetooth デバイスを検出できない場合は、Bluetooth デバイスがオンになっており、アドバタイジングされていることを確認してください。

于 2013-08-30T20:46:10.873 に答える