Maraca Library

The Socket Mobile Rumba iOS application is designed to bridge our Socket Mobile RFID readers and scanners with a web application.

This is possible through leveraging the Socket Mobile Maraca and Capture iOS cocoapods in order to interact with a web application using our Capture Javascript SDK.

The Rumba iOS application loads the web application into a WKWebView. The web application will send data through specified Capture Javascript SDK functions which are received in the WKWebView and then finally, passed on to the Rumba iOS application.

At this point, Maraca will take over. Based on the data that Maraca receives, it will interact with the Capture iOS cocoapod.

Getting started with Capture and Maraca

Step One / Five

Initialize the Capture and Maraca instances

// First, import WebKit to use the WKWebView and other WebKit related classes / delegates
import WebKit
// Import SKTCapture to use the Capture cocoapod and its delegates
import SKTCapture


// Step TWO
// Initialize a CaptureHelper instance
// Note, this is a singleton so there is no need to initialize more than once
private var capture = CaptureHelper.sharedInstance

// Initialize a lazy Maraca instance
// The `lazy` keyword is needed to refer to the CaptureHelper instance and `self`,
// otherwise there will be an error.
// Optionally, you may declare this is an optional and instantiate
// in `viewDidLoad` or elsewhere.
private lazy var maraca = Maraca(capture: capture, delegate: self)

Step Two / Five

Set up the CaptureHelper instance with your AppInfo. NOTE: This should be called in viewDidLoad

// Omitted ...

private func setupCapture() {

    // You should have received these values when you register your iOS application
    // on our developer portal
    let AppInfo = SKTAppInfo()
    AppInfo.appKey="...."
    AppInfo.appID="...."
    AppInfo.developerID="...."

    // open Capture Helper only once in the application
    capture.dispatchQueue = DispatchQueue.main
    capture.pushDelegate(self)
    capture.openWithAppInfo(AppInfo) { [weak self] (result) in
        guard let strongSelf = self else { return }
        print("Result of Capture initialization: \(result.rawValue)")

        if result == SKTResult.E_NOERROR {
            // ....
        }
    }
}

Step Three / Five

// Initialize two `WKWebViewConfiguration` and `WKUserContentController`
// `vars` which will be modified
private var webViewConfiguration = WKWebViewConfiguration()
private var userContentController = WKUserContentController()

// Omitted ...

override func viewDidLoad() {
    super.viewDidLoad()

    setupCapture() // From step One.5
    setupWebviewConfiguration()
}

private func setupWebviewConfiguration() {
    webViewConfiguration.applicationNameForUserAgent = "..Name-of-your-ios-application."
    // wire the user content controller to this view controller and to the webView config

    // NOTE
    // There is a known memory-leak issue associated with this function
    userContentController.add(self, name: "observe")
    webViewConfiguration.userContentController = userContentController

    maraca.addMessageHandlers(to: userContentController, scriptMessageHandler: self)
}

Step Four / Five

When initializing the WKWebView, you must pass in the webViewConfiguration from Step Three

var webView: WKWebView!

// Omitted ...

private func setupWKWebView() {
    webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)
    webView.navigationDelegate = self
    webView.scrollView.delegate = self

    view.addSubview(webView)
}

Step Five / Five

It is important to extend the WKScriptMessageHandler

// MARK: - WKScriptMessageHandler

extension WebviewController: WKScriptMessageHandler {

  func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {

      guard let messageBody = message.body as? String, let webview = message.webView else {
          return
      }

      // This is the final step
      if maraca.didReceiveCaptureJSMessage(message: message) {
          return
      }

      // Omitted ...

  }
}

Optional Features

Extending the Maraca delegate

// MARK: - MaracaDelegate

extension ViewController: MaracaDelegate {

  func maraca(_ maraca: Maraca, didReceive decodedData: SKTCaptureDecodedData?, from device: CaptureHelperDevice) {

  }

  func maraca(_ maraca: Maraca, webviewDidOpenCaptureWith client: Client) {

  }

  func maraca(_ maraca: Maraca, webviewDidCloseCaptureWith client: Client) {

  }
}

Activating, resigning and getting Clients

public func activateClient(at indexPath: IndexPath) {

}

public func activateClient(_ client: Client) {

}

public func resignActiveClient() {

}

public func closeAndDeleteClient(_ client: Client) {

}






// Getters

public func getClient(for clientHandle: ClientHandle) -> Client? {

}

There will be more information as soon as the Maraca Library is released.

Please check again later, or send an email to sdksupport@socketmobile.com to be notified when Maraca is available.