Kogarasi / BlueCompass

Routing for WKScriptMessage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BlueCompass

CI Status Version License Platform

Features

  • Reactive Style.
  • Simple receive data with type.

Example

// format for receive json.
class MessageEntity: Decodable {
  var message: String
}


class ExampleViewController: UIViewController {
  var disposeBag = DisposeBag()
  
  let blueCompass = BlueCompass()
  
  // create configuration and set BlueCompass to userContentController.
  lazy var configuration: WKWebViewConfiguration = {
    let config = WKWebViewConfiguration()
    config.userContentController = blueCompass
    
    return config
  }()
  
  override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear( animated )
    
    let webView = WKWebView( frame: view.frame, configuration: configuration )
    view.addSubview( webView )
    
    // "test" is custom specified name.
    // Json data is converted in internal.
    blueCompass.receive( "test", MessageEntity.self ).subscribe{
      print( $0.element!.message )
    }.disposed(by: disposeBag )
    
    // javascript sample.
    webView.evaluateJavaScript( "webkit.messageHandlers.test.postMessage( JSON.stringify( { message: \"hello world\" } ) )" )
  }
}

Requirements

Swift: 5.0 iOS: 11.0 RxSwift: 5.0

Installation

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

pod 'BlueCompass'

Author

kogarasi, kogarasi.cross@gmail.com

License

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

About

Routing for WKScriptMessage

License:MIT License


Languages

Language:Swift 74.2%Language:Ruby 25.8%