1
votes

is it possible to configure a bluetooth-device in a way that my app automatically connects to it when near - without pairing etc.?

The device will be custom built and the app will be written by me, I first have to define some specs. It would be great if there's an option in the device that as soon as it's near my (opened) app that both are connected automatically without any setup process.

1
That bears a security risk - you could automate the pairing process by having a fixed passcode. But this caused a lot of security problems in the past w/ default 0000 codes. - Tobi Nary
but is it possible to build the devices with unique passcodes and if that passcode is known to the app that it connects automatically without any pairing? - swalkner
Well, technically, the pairing would still take place but user interaction can be unneccesary. Yet, I do not know if apples APIs allow for pairing w/o user interaction. - Tobi Nary
BLE devices often connect without bonding (which is different to pairing but the term pairing is often used when bonding is meant). - Paulw11

1 Answers

1
votes

Sure you can. If the device will be custom made and you know its characteristics

Code below (TRANSFER_SERVICE_UUID - GUID of your device):

 _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];

  }
}