I've got the following code:
self.bluetoothDeviceManager = [WLXBluetoothDeviceManager deviceManager];
id<WLXBluetoothDeviceRepository> repository = [[WLXBluetoothDeviceUserDefaultsRepository alloc] initWithUserDefaults:[NSUserDefaults standardUserDefaults]];
WLXBluetoothDeviceRegistry * registry = [self.bluetoothDeviceManager deviceRegistryWithRepository:repository];
registry.enabled = YES;
[registry fetchLastConnectedPeripheralWithBlock:^(NSError *error, CBPeripheral *peripheral) {
if (peripheral) {
// Connect
[self connectToPeripheral:peripheral];
}
else
{
// Discover
NSObject<WLXDeviceDiscoverer> *discoverer = self.bluetoothDeviceManager.discoverer;
discoverer.delegate = self;
[discoverer discoverDevicesNamed:@"MyDeviceName" withServices:nil andTimeout:30000];
}
}];
Later on in the flow, I consistently get a connection. But the peripheral variable in the fetchLastConnectedPeripheralWithBlock always comes back nil on next run. In addition the wiki says there's a property called lastConnectedPeripheral on the object we should use, rather than the block-based method.
I've got the following code:
Later on in the flow, I consistently get a connection. But the peripheral variable in the fetchLastConnectedPeripheralWithBlock always comes back nil on next run. In addition the wiki says there's a property called lastConnectedPeripheral on the object we should use, rather than the block-based method.