Maraca Library

The Socket Mobile Maraca open-source cocoapod is designed to bridge our Socket Mobile RFID readers and barcode scanners with a web application.

This is possible through leveraging the Socket Mobile Capture iOS open-source cocoapod in order to interact with a web application using our Capture Javascript SDK.

First, the iOS application needs to load 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, interpreted by the Maraca SDK.

At this point, Maraca will then perform the correct action based on received data. There are actions that are specific to Maraca / Capture Javascript and there are those that are specified by the iOS application. i.e., you may provide your own expected actions to Maraca. These will be referred to as “message handlers”.

Setting up Maraca

There are four functions used in setting up the Maraca singleton:

@discardableResult
public func injectCustomJavascript(mainBundle: Bundle, javascriptFileNames: [String]) -> Maraca {
    // An optional function. You can inject your own custom javascript from your iOS application
    // into the web application using Javascript files within the same Bundle.
    // Simply specify the Javascript file name as it appears in your Bundle / file list.
}

@discardableResult
public func observeJavascriptMessageHandlers(_ customMessageHandlers: [String]? = nil) -> Maraca {
    // Not optional. However, you may also register message handlers to be observed as they are
    // sent from the web application. For example, if you'd like the iOS application to perform some action
    // at a desired time, you specify a message handler
}

@discardableResult
public func setDelegate(to: MaracaDelegate) -> Maraca {
    // An optional function. This will set the current UIViewController, NSObject, etc. as the delegate
    // as long as it extends the MaracaDelegate.
}

public func begin(withAppKey appKey: String, appId: String, developerId: String, completion: ((Bool) -> ())? = nil) {
    // Final step. Specify the three necessary parameters for opening SKTCapture here.
}

Putting it all together

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




override func viewDidLoad() {
    super.viewDidLoad()
    setupMaraca()
}

// Step TWO
// Setup the Maraca singleton. NOTE, this does not need to be initialized again.
// It can be used anywhere in your application afterward.
private func setupMaraca() {
  // Use the values provided when you registered your application on the Socket Mobile developer site.
  // This is necessary to using Maraca and Capture together.
  let appKey =        <Your app key>
  let appId =         <Your app ID>
  let developerId =   <Your developer ID>

  let javascriptFileNames = [...]
  let messageHandlers: [String] = [...]


  Maraca.shared.injectCustomJavascript(mainBundle: Bundle.main, javascriptFileNames: javascriptFileNames)
      .observeJavascriptMessageHandlers(messageHandlers)
      .setDelegate(to: self)
      .begin(withAppKey: appKey,
             appId: appId,
             developerId: developerId,
             completion: { (completed) in

              // Do something on completion
      })
}

Optional Features

Extending the Maraca delegate

// MARK: - MaracaDelegate

extension ViewController: MaracaDelegate {

    // Notifies the delegate that a client has been opened by the web application.
    // A client is a bridge between the web application and the iOS application
    // using Maraca.
    // This allows the Socket Mobile Capture SDK to interact with the web application.
    // Examples include connecting a Socket Mobile barcode scanner or RFID reader and
    // passing information to and from the web application.

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

    }

    // Notifies the delegate that the web application has closed the client.
    // Thus closing this bridge between the Socket Mobile Capture SDK and
    // web application, including all connected Socket Mobile barcode scanners
    // and RFID readers.

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

    }

    // Notifies the delegate, that the web application has sent a "WKScriptMessage"
    // that is not related to Maraca / Capture Javascript SDK.
    // i.e., this one of the custom message handlers that you may have specified
    // during initialization of Maraca.
    // If you are not familiar with WebKit WKScriptMessages, consider taking a look
    // at Apple's documentation.
    // But, it is an object that contains the title of the desired action as well
    // as a "body", which may contain some extra payload data.
    // The web application uses this to send data back to the iOS application.

    func maraca(_ maraca: Maraca, didReceive scriptMessage: WKScriptMessage) {

    }
}

Activating, resigning and getting Clients

// NOTE*
// These functions are intended for iOS applications that manage
// multiple WKWebViews.
// For example, if the application manages a set of tabs containing
// their own WKWebViews.
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.