WebViewJavascriptBridge

repository·master·Indexed 12 days ago

https://github.com/marcuswestin/webviewjavascriptbridge

An iOS/OSX library enabling bidirectional message passing between Objective-C and JavaScript within WKWebViews, UIWebViews, and standard WebViews.

Tokens
297
Snippets
1
Records
3
Agent score
46%

What's inside WebViewJavascriptBridge

  1. How to use WebViewJavascriptBridge in an iOS/OSX project

    master

    To implement the bridge, follow these five steps:

    1. Import and Declare: Import the header and declare a property for the bridge.
    2. Instantiate: Create the bridge instance using the web view.
    3. Register/Call Handlers: Set up communication between Obj-C and JS.
    4. JS Setup: Copy the setupWebViewJavascriptBridge snippet into your JavaScript code to initialize the bridge.
    5. Initialize App: Call setupWebViewJavascriptBridge to access the bridge object.

    Obj-C Implementation

    #import "WebViewJavascriptBridge.h"
    
    // Declare property
    @property WebViewJavascriptBridge* bridge;
    
    // Instantiate
    self.bridge = [WebViewJavascriptBridge bridgeForWebView:webView];
    
    // Register an Obj-C handler
    [self.bridge registerHandler:@