2013-05-21 4 views
1

Я делаю приложение для iPhone, и мне нужно получить соседние устройства Bluetooth. Я использую CoreBluetooth Framework, и это не работает. Я знаю, что эта инфраструктура предназначена только для Bluetooth Low Energy, поэтому я купил адаптер bluetooth 4.0 usb, поддерживающий Low-Energy. Я проверяю это приложение в моем iPhone 5. Это мой кодIphone обнаруживает устройства bluetooth

- (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 устройство. Мне нужно решение для этого, я с ума сошел. спасибо.

+0

В итоге у меня возникла аналогичная проблема. Вы нашли решение здесь? – Abhinav

ответ

0

Вы уверены, что 180A - это правильный сервис?

Если бы не попробовать:

[mgr scanForPeripheralsWithServices:nil options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]; 
+0

Я пробовал все сервисы posibles, и я пробовал устанавливать сервисы как ноль. Это не работает. Я сдаюсь, но спасибо. – Arturo18

+0

Вы проверили это: https://developer.apple.com/library/ios/#samplecode/BTLE_Transfer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012927? – Aboelseoud

0

Ваш код кажется нормально. Search the app store for TI BLE for their free iPhone app.

Если их приложение не может обнаружить ваше устройство Bluetooth, убедитесь, что ваше устройство bluetooth включено и является рекламой.

Смежные вопросы