Sundus Alamovic Sundus Alamovic - 29 days ago 15
iOS Question

BLE in iOS with VIPER

I am developing an iOS BLE application and everything works great. I am handling BLE in a singleton class that calls its

method in the view controller's
. From there on I connect with devices and exchange data.

Now I'm trying to implement VIPER architecture in my app and I cant quite figure where this BLE part will be placed. Because currently my BLE code is activated when the view displays. I came up with the following scheme: Place the ble scanning in the presenter, and once the view comes into memory, request the presenter to start scanning. The presenter will ask the BLE singleton to scan with appropriate UUIDs and once data is received, inform Interactor to store it into the DB and then update UI.

This is my first project with VIPER and I'd really appreciate any comments or suggestions. Thanks!


Incase anybody wanders over here looking for the same problem, this is what I ended up doing:

I placed the calls to the ble singleton in the interactor. So when the user taps on the UI for ble scan, presenter.startBleScan() and interface.showUpdatingBleDevices() are called on the UI.

The presenter then calls interactor.startBleScan().

The interactor talks to the singleton class and calls presenter.didReceiveNewBleDevices(count: 5) on the presenter

After this, the presenter calls interface.hideUpdateBle() and interface.showNewDevices