无法发现我的扫描仪

时间:2016-06-01 06:06:58

标签: objective-c bluetooth

我想通过蓝牙连接我的扫描仪与我的应用程序,因为我推荐了这个教程https://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor,但是我在这里添加了我的uuid但是它没有发现我的扫描仪,请帮我发现我的扫描仪 这是我根据教程尝试的编码:

UUID:00001101-0000-1000-8000-00805F9B34FB

- (void)viewDidLoad
 {
[super viewDidLoad];

NSArray *services = @[[CBUUID UUIDWithString:BLE_Devices]];
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];  
self.centralManager = centralManager;

}

- (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");
    NSLog(@"%@",self.services);

    [central scanForPeripheralsWithServices:self.services options:nil];

}
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");
}}

// - 使用CBPeripheral类作为主输入参数调用它。这包含了关于BLE外围设备的大部分信息。

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
{
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
NSLog(@"%@ The adverstisementData is:",advertisementData);

if ([localName length ]> 0)
{

//if (![localName isEqual:@""]) {
    NSLog(@"%@ Local Name:",localName);
    // We found the Heart Rate Monitor
    [self.centralManager stopScan];
    self.polarH7HRMPeripheral = peripheral;
    peripheral.delegate = self;
    [self.centralManager connectPeripheral:peripheral options:nil];
}}

centralManagerDidUpdateState:方法工作正常, 请帮我连接扫描仪。

Please see here ,my scanner is connected via bluetooth in my iPod touch

0 个答案:

没有答案