【问题标题】:automatically connect to bluetooth device without pairing无需配对自动连接蓝牙设备
【发布时间】:2016-01-22 10:15:17
【问题描述】:

是否可以配置蓝牙设备,使我的应用在靠近时自动连接到它 - 无需配对等?

设备将是定制的,应用程序将由我编写,我首先必须定义一些规格。如果设备中有一个选项,只要它靠近我的(打开的)应用程序就可以自动连接而无需任何设置过程。

【问题讨论】:

  • 这存在安全风险 - 您可以通过使用固定密码来自动执行配对过程。但这在过去使用默认 0000 代码时导致了很多安全问题。
  • 但是是否可以使用唯一密码构建设备,如果应用知道该密码,它会自动连接而无需任何配对?
  • 好吧,从技术上讲,配对仍然会发生,但用户交互可能是不必要的。然而,我不知道苹果 API 是否允许在没有用户交互的情况下配对。
  • BLE 设备通常在没有绑定的情况下连接(这与配对不同,但在表示绑定时通常使用术语配对)。

标签: ios bluetooth bluetooth-lowenergy


【解决方案1】:

当然可以。如果设备是定制的并且你知道它的特性

以下代码(TRANSFER_SERVICE_UUID - 您设备的 GUID):

 _centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];


- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
// You should test all scenarios
 if (central.state != CBCentralManagerStatePoweredOn) {
    [self stop];
    return;
 }

if (central.state == CBCentralManagerStatePoweredOn) {
    // Scan for devices
    [_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:TRANSFER_SERVICE_UUID]] options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];
    NSLog(@"Scanning started");

    if(_delegate)
    {
        if([_delegate respondsToSelector:@selector(CB_changedStatus:message:)])
        {
            [_delegate CB_changedStatus:CBManagerMessage_ScanningStarted message:@"Scanning started"];
        }
    }
  }
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {

NSLog(@"Discovered %@ at %@", peripheral.name, RSSI);

if (_discoveredPeripheral != peripheral) {
    // Save a local copy of the peripheral, so CoreBluetooth doesn't get rid of it
    _discoveredPeripheral = peripheral;



    // And connect
    NSLog(@"Connecting to peripheral %@", peripheral);

    if(_delegate)
    {
        if([_delegate respondsToSelector:@selector(CB_changedStatus:message:)])
        {
            [_delegate CB_changedStatus:CBManagerMessage_ConnectingToPeripheral message:[NSString stringWithFormat:@"Connecting to peripheral %@", peripheral]];
        }
    }

    [_centralManager connectPeripheral:peripheral options:nil];

  }
}

【讨论】:

    猜你喜欢
    • 2015-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2015-01-18
    相关资源
    最近更新 更多