Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebViewを活用するアプリの作り方 LT @ Conference With Develo...

cockscomb
February 01, 2014

WebViewを活用するアプリの作り方 LT @ Conference With Developers 2

cockscomb

February 01, 2014
Tweet

More Decks by cockscomb

Other Decks in Programming

Transcript

  1. self.bridge = [WebViewJavascriptBridge bridgeForWebView:self.webView webViewDelegate:self handler:^(id data, WVJBResponseCallback responseCallback) {

    }]; ! [self.bridge registerHandler:@"objc-handler" handler:^(NSDictionary *data, WVJBResponseCallback responseCallback) { // do something responseCallback(@{}); }]; [self.bridge callHandler:@"js-handler" data:@{ @"key" : @"value" } responseCallback:^(id responseData) { // do something }];
  2. var Bridge = {}; Bridge.connect = function(callback) { if (window.WebViewJavascriptBridge)

    { callback(WebViewJavascriptBridge); } else { document.addEventListener('WebViewJavascriptBridgeReady', function() { callback(WebViewJavascriptBridge); }, false); } }; ! Bridge.connect(function(bridge) { bridge.init(function (message, responseCallback) { if (responseCallback) { responseCallback(); } }); ! bridge.registerHandler('js-handler', function (responseData) { // do something }); ! bridge.callHandler(‘objc-handler', { 'key' : 'value' }, function responseCallback(responseData) { // do something }); });
  3. JSContext *context = [self.webView valueForKeyPath: @"documentView.webView.mainFrame.javaScriptContext"]; JSValue *three = [context

    evaluateScript:@"1+2"]; http://blog.impathic.com/post/64171814244/true-javascript-uiwebview-integration-in-ios7