Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registry lastConnectedPeripheral is always nil #48

Open
drdaz opened this issue Jan 7, 2016 · 7 comments
Open

Registry lastConnectedPeripheral is always nil #48

drdaz opened this issue Jan 7, 2016 · 7 comments
Assignees

Comments

@drdaz
Copy link
Contributor

drdaz commented Jan 7, 2016

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.

@guidomb
Copy link

guidomb commented Jan 7, 2016

When the peripheral parameter in the block passed to fetchLastConnectedPeripheralWithBlock is nil do you also get nil in the error parameter?

@guidomb
Copy link

guidomb commented Jan 7, 2016

After checking the code, I realized that the documentation was not up-to-date. The main responsibility of the registry is just to listen to connection event and save the peripheral in the corresponding repository. I would update the documentation to say that fetchLastConnectedPeripheralWithBlock should be used.

@guidomb guidomb self-assigned this Jan 7, 2016
@drdaz
Copy link
Contributor Author

drdaz commented Jan 7, 2016

When the peripheral parameter in the block passed to fetchLastConnectedPeripheralWithBlock is nil do you also get nil in the error parameter?

Both variables are nil, yes.

@guidomb
Copy link

guidomb commented Jan 7, 2016

OK that is weird and definitely a bug. I am gonna try to reproduce that and see where the bug is.

@guidomb
Copy link

guidomb commented Jan 7, 2016

I cannot find a way to reproduce the bug, would you mind sharing your example project @drdaz ?

@drdaz
Copy link
Contributor Author

drdaz commented Jan 8, 2016

Here... use the .xcworkspace file to open the project.
Hopspots_Comms 2.zip

@guidomb
Copy link

guidomb commented Jan 11, 2016

@drdaz Try using this project https://github.com/Wolox/WLXBluetoothDeviceExample. I will connect to the first device that founds and then I will fetch it from the local repository. Let me know if you can reproduce the bug with that project.

Remember to run carthage bootstrap --platform ios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants