Я делаю приложение для 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 устройство. Мне нужно решение для этого, я с ума сошел. спасибо.
В итоге у меня возникла аналогичная проблема. Вы нашли решение здесь? – Abhinav