To allow your app to receive the status of the different services used by to the SDK, a ProximityHealthCheckListener must be registered to the herowInitializer.

Using these statuses, you can adapt the user interface depending of the availability of the various services used by the SDK.

Register the ProximityHealthCheckListener

  • Open a ViewController

  • Import the ConnectPlaceCommon package to the ViewController

Switch to Swift

@import ConnectPlaceCommon;
import ConnectPlaceCommon;
  • Add it the ProximityHealthCheckDelegate

Switch to Swift

@interface ViewController : UIViewController <ProximityHealthCheckDelegate>
class ViewController: UIViewController, ProximityHealthCheckDelegate
  • In the viewWillAppear method, register the ViewController to the herowInitializer using the registerProximityHealthCheckDelegate method

Switch to Swift

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [herowInitializer registerProximityHealthCheckDelegate:self];
}
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    herowInitializer?.registerProximityHealthCheckDelegate(self)
}

Note:

You can also decide to make your application notify only about the status update of specific services. This can be achieved by adding at end of the method, the list of the services for which your application must be notified in the event of an update:

Switch to Swift

- (void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [herowInitializer registerProximityHealthCheckDelegate:self];
}
override func viewWillAppear(_ animated: Bool) {
 super.viewWillAppear(animated)
 herowInitializer?.registerProximityHealthCheckDelegate(self)

}


In this example, the **ViewController** will be notified about the status update of **the services 1 and 2**

Unregister the ProximityHealthCheckListener

  • In the viewWillDisappear method, register the ViewController to the herowInitializer using the unregisterProximityHealthCheckDelegate method

Switch to Swift

- (void) viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [herowInitializer unregisterProximityHealthCheckDelegate:self];
}
override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    herowInitializer?.unregisterProximityHealthCheckDelegate(self)
}

Note:

You can find a concrete implementation of the registration process in the source code of the the quickstart tutorial in our github repo.

Implements the onProximityHealthCheckUpdate method

The onProximityHealthCheckUpdate method takes one parameter called HealthStatus. This object possesses two variables:

  • isDown: a boolean which allows you to know if any services have been touched.
  • Map<Integer, ServiceStatus>: a map of all the services available in the SDK associated with their type. You can consult the exhaustive list of services and their type in the following document.

The ServiceStatus object contains:

  • isDown: the current status of the service.
  • List: a list of Status. A status contains a subtype and the associated message to it.

As soon as an error occurs in a service, the isDown Boolean is set to true and an error is added to the list of status. You just have to loop, on every service and adapt your interface according to the current status.

Pratical example

Let's see a simple example to clear your minds!

We want to check if the bluetooth has any issues.

We check the current code of the bluetooth service: it's 3.

So to be able to react of any bluetooth issues, we just need to monitor the type 3 and listen the subtype which we are interested in.

Switch to Swift

- (void) onProximityHealthCheckUpdate:(HealthStatus * _Nonnull) healthStatus {
    if ([healthStatus isDown]) {
        for (ServiceStatus* service in healthStatus.serviceStatusMap.allValues) {
            if ([service isDown]) {
                if ([service type] == 3) {
                    if ([service containsStatusWithCode:32]) {
                        textViewErrors.text = "Your device does not support Bluetooth LE.";
                    } else {
                        textViewErrors.text = "The bluetooth is unactive, please activate it to let the scan begin.";
                    }
                }
            }
        }
    } else {
        self.textViewErrors.text = @"";
    }
}
public func onProximityHealthCheckUpdate(_ healthStatus: HealthStatus) {
    if healthStatus.isDown {
        for service in healthStatus.serviceStatusMap.values {
            if service.isDown() {
                if service.type == 3 {
                    if service.containsStatus(code: 32) {
                        textViewErrors.text = "Your device does not support Bluetooth LE.";
                    } else {
                        textViewErrors.text = "The bluetooth is unactive, please activate it to let the scan begin.";
                    }
                }
            }
        }
    } else {
        textViewErrors.text = ""
    }
}