iPhone 응용 프로그램을 사용하고 있으며, 포도당 측정을 위해 블루투스 장치로 연결하려고합니다. 기기는 here에서 찾을 수 있습니다.코어에서 주변 장치를 찾을 수 없음 Bluetooth
코어 블루투스에 관한 Apple의 문서를 읽은 후, 나는이 tutorial을 읽기 시작했습니다. 또한이 링크에서 블루투스 장치 용 서비스 ID를 얻습니다. here
그래서 기초를 이해 한 후 튜토리얼 에서처럼 코드를 작성하기 시작했습니다.
그리고이 내 코드 : 나는 CBCentralManagerDelegate 및 CBPeripheralDelegate
의 대표를 구현했습니다#define POLARH7_HRM_DEVICE_INFO_SERVICE_UUID @"180A" // for Device Information service.
#define POLARH7_HRM_HEART_RATE_SERVICE_UUID @"1808" // For Glucose service.
NSArray *services = @[[CBUUID UUIDWithString:POLARH7_HRM_HEART_RATE_SERVICE_UUID], [CBUUID UUIDWithString:POLARH7_HRM_DEVICE_INFO_SERVICE_UUID]];
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[centralManager scanForPeripheralsWithServices:services options:nil];
self.centralManager = centralManager;
그리고
나는 centralManagerDidUpdateState
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
// Determine the state of the peripheral
if ([central state] == CBCentralManagerStatePoweredOff) {
NSLog(@"CoreBluetooth BLE hardware is powered off");
}
else if ([central state] == CBCentralManagerStatePoweredOn) {
NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
}
else if ([central state] == CBCentralManagerStateUnauthorized) {
NSLog(@"CoreBluetooth BLE state is unauthorized");
}
else if ([central state] == CBCentralManagerStateUnknown) {
NSLog(@"CoreBluetooth BLE state is unknown");
}
else if ([central state] == CBCentralManagerStateUnsupported) {
NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
}
}
내 NSLog 로그에 대한 알림을받을 : CoreBluetooth BLE hardware is powered on and ready.
그러나 central didDiscoverPeripheral
에 대한 알림을받지 못했습니다.
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
if ([localName length] > 0) {
NSLog(@"Found the heart rate monitor: %@", localName);
[self.centralManager stopScan];
self.polarH7HRMPeripheral = peripheral;
peripheral.delegate = self;
[self.centralManager connectPeripheral:peripheral options:nil];
}
}
이 메소드는 호출되지 않습니다.
중앙 (내 iPhone)이 내 포도당 장치 인 주변 장치를 찾지 못했습니다.
설정 -> 블루투스에서 장치를 검색 할 때 장치를 찾을 수 없습니다.
시도해보십시오.'[centralManager scanForPeripheralsWithServices : nil options : nil];'그러면 알 수 있습니다. 귀하의 장치가 정말로 BLE인지, 링크가 없는지 나는 알지 못했고,'centralManagerDidUpdateState'를'CBCentralManagerStatePoweredOn'으로했을 때 검사를 했습니까? – Larme
[중앙 관리자 scanForPeripheralsWithServices : nil 옵션 : nil]; 하지만 didDiscoverPeripheral 대리자에서 알림을받지 못했습니다. – Abo3atef