Basics

Guide on how to call operations & handle callbacks in the SDK

NotchService code references might not be equal to the current syntax of the SDK. However, in all cases, you could easily find the appropriate method in the SDK if you use intellisense.

Callbacks & cancellation

You can interact with the notches by using the NotchService.

Each service calls return a NotchCancellable .cancel() that will stop the process. IMPORTANT Do not cancel an already canceled operation to avoid inconsistency.

Each service call has four function parameters to act as callback functions:

  • onSuccess is called when the process finishes with a success alongside with the result object.
  • onFailure is called when the process finishes with a failure with a NotchError.
  • onProgress is optionally called during the process. For example, during pairing. See more at NotchProgress.
  • onCancelled is called if the call’s .cancel() the function was called. It has no input parameter.

Example for starting a timed capture:

  • 
              
        cancellable = mNotchService.timedCapture(true, new NotchCallback<Measurement>() {
            @Override
            public void onProgress(@Nonnull NotchProgress notchProgress) {
                // Handle progress
            }
    
            @Override
            public void onSuccess(@Nullable Measurement measurement) {
                // Handle success
            }
    
            @Override
            public void onFailure(@Nonnull NotchError notchError) {
                // Handle failure
            }
    
            @Override
            public void onCancelled() {
                cancellable = null;
            }
        });
            
  • 
            
        currentCancellable = service.timedCapture(
            success: { result in
                // Handle success
            },
            failure: { result in
                switch result {
                case .unknownError(let message)
                    self.showCaptureFailedAlert(message: message)
                default:
                    self.showCaptureFailedAlert(message: "Internal error")
                }
                self.currentCancellable = nil
            },
            progress: { _ in 
                // Handle progress
            },
            cancelled: {
                currentCancellable = nil 
        })
          

You can define an EmptyCallback to add default implementation for all the callbacks and let’s override always the necessary ones.

  • 
              
        public class EmptyCallback<T> implements NotchCallback<T> {
            @Override
            public void onProgress(NotchProgress notchProgress) {
                // Handle your progress
            }
    
            @Override
            public void onSuccess(T t) {
                // Handle your success
            }
    
            @Override
            public void onFailure(NotchError notchError) {
                // Handle your failure
            }
    
            @Override
            public void onCancelled() {
            }}
            
  • 
            
        class NotchCallback<Type>: NotchCallbackType {      
            typealias T = Type
            private let successCallback: ((Type) -> Void)
            private let errorCallback: ((NotchError) -> Void)
            
            init(successCallback: @escaping ((Type) -> Void),
                errorCallback: @escaping ((NotchError) -> Void)) {
                self.successCallback = successCallback
                self.errorCallback = errorCallback
            }
            
            func progress(_ progress: NotchProgress) {
                // Not interested here
            }
            
            func success(_ result: Type) {
                successCallback(result)
            }
            
            func failure(_ error: NotchError) {
                errorCallback(error)
            }
            
            func cancelled() {
                
            }}
          

Threading

Each service call happens on the background thread. The callbacks are always received on the same background thread, DO NOT forget to switch back to the main thread if you perform actions on the UI.


Setting Up - Android
User handling