$30 off During Our Annual Pro Sale. View Details »

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

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. cockscomb

  2. None
  3. ͸ͯͳϒϩά

  4. 8FC"1*Λར༻͢ΔJ04ΞϓϦ։ൃ ͸ͯͳαϚʔΠϯλʔϯγοϓ

  5. –id:griffin-stewie lͦΕͳΓʹ࣮ઓܦݧ͕͋ΔਓͰ΋ ΍ͬͯͳͦ͞͏ͩͬͨΓ஌Βͳͦ͏ͳ͜ͱΛ αϥοͱݟͤͯ͘Ε͍ͯΔz

  6. )BUFOB&OHJOFFS4FNJOBS ͸ͯͳʹ͓͚ΔϞμϯJ04ΞϓϦ։ൃೖ໳

  7. – @kazuph lϞμϯʹॻ͔ͳ͔ͬͨ৔߹ͱॻ͍ͨ৔߹Λίʔ υͰൺֱͨ͠΍ͭͷͰઆ໌Λͯ͘͠ΕͯΔͷͰ ͍͢͝ḿΔIBUFOBUFDIz

  8. cockscomb

  9. 8FC7JFXΛ׆༻͢Δ ΞϓϦͷ࡞Γํ

  10. 6*ͱͯ͠ͷ8FC7JFX w 6*8FC7JFXͰ)5.-ΞϓϦΛ࡞Δ w ΞϓϦͷҰ෦͚ͩ)5.-Ͱ࡞Δ w +BWB4DSJQUͱωΠςΟϒͷؒΛͲ͏औ Γ͔࣋ͭ

  11. w "QBDIF$PSEPWB "EPCF1IPOF(BQ  w 6*8FC7JFX w +BWB4DSJQU$PSF w 8FC7JFX+BWB4DSJQU#SJEHF

  12. "QBDIF$PSEPWB w 6*8FC7JFXΛӅṭ w ϓϥάΠϯΞʔΩςΫνϟ w ϚϧνϓϥοτϑΥʔϜ

  13. 6*8FC7JFX • -stringByEvaluating
 JavaScriptFromString: • -webView:
 shouldStartLoadWithRequest:
 navigationType:

  14. 8FC7JFX+BWB4DSJQU#SJEHF w HJUIVCDPNNBSDVTXFTUJO 8FC7JFX+BWBTDSJQU#SJEHF w 8FCίϯςϯπͱωΠςΟϒͷ΍Γऔ ΓΛந৅Խ

  15. 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 }];
  16. 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 }); });
  17. 8FC7JFX+BWB4DSJQU#SJEHF w ωΠςΟϒଆͱ8FCίϯςϯπଆɺ૒ ํ޲ͷݺͼग़͠ɺσʔλͷड͚౉͠ w ബ͘ίϯτϩʔϧ͠΍͍͢Ϧʔζφϒ ϧͳΠϯλʔϑΣʔε

  18. +BWB4DSJQU$PSF

  19. 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
  20. 6*8FC7JFX +BWB4DSJQU$PSF w ඇެ։"1* w +BWB4DSJQU$PSFͷߴ౓ͳ࢓૊Έ w কདྷͷJ04΁ͷظ଴

  21. 8FC7JFXΛ׆༻͢Δ ΞϓϦͷ࡞Γํ

  22. DPDLTDPNCIBUFOBCMPHDPN

  23. IBUFOBDPSQKQSFDSVJU