Maraca 1.0.6

Maraca 1.0.6

Maintained by Chrishon Wyllie, Socket Mobile.



Maraca 1.0.6

  • By
  • Socket

Maraca

CI Status Version License Platform

Maraca establishes connections between your iOS application using our iOS Capture SDK and a web application using our CaptureJS SDK. This enables the web application to connect with our scanners and NFC readers with the same flexibilty that our iOS SDK provides.

Usage

Under the hood, Maraca is an umbrella for our iOS Capture SDK. So naturally, you need to provide credentials to get started.

The most important step is to call observeJavascriptMessageHandlers(_:) You may provide your own Javascript Message Handler names if you're familiar with WKUserContentController. Otherwise, this can be nil. This function enables messages containing data to be transferred from your web application using CaptureJS to your iOS application.

Inside the completion handler of beging(withAppKey:appId:developerId:completion:), create your WKWebView using the public Maraca.shared.webViewConfiguration configuration

override func viewDidLoad() {
    super.viewDidLoad()

    setupMaraca()
}

private func setupMaraca() {
    
    let appKey =        <Your App Key>
    let appId =         <Your App ID>
    let developerId =   <Your Developer ID>
    let bundle = Bundle.main
    
    Maraca.shared.injectCustomJavascript(mainBundle: bundle, javascriptFileNames: ["getInputForDecodedData"])
        .observeJavascriptMessageHandlers(YourOwnMessageHandlers.allCases.map { $0.rawValue })
        .setDelegate(to: self)
        .begin(withAppKey: appKey,
               appId: appId,
               developerId: developerId,
               completion: { [weak self] (result) in

                    if result == .E_NOERROR {
                        self?.setupUI()
                    } else {
                        // Encountered some error, inspect result
                    }
        })
}

// Initialize WKWebView with Maraca.shared.webViewConfiguration after
// setting up Maraca
private var webview: WKWebView!

private func setupUI() {

    webview = {
        let w = WKWebView(frame: .zero, configuration: Maraca.shared.webViewConfiguration)
        w.navigationDelegate = self
        return w
    }()
    
    view.addSubview(webview)
    
    // Set up constraints, etc..
    
    let myWebApplicationURLString = .....
    
    guard let url = URL(string: myWebApplicationURLString) else {
        return
    }
    
    loadMyWebApplication(with: url)
    
}

Documentation

Full documentation can be found here

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

Maraca is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Maraca'

Author

Chrishon, [email protected]

License

Maraca is available under the MIT license. See the LICENSE file for more info.