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

Introduction to WebKitPlus

07236dd218acc51812c47f92cd6bba19?s=47 yashigani
April 15, 2015

Introduction to WebKitPlus

Introduction to WebKitPlus at potatotips #16.
Check it!!! -> https://github.com/yashigani/WebKitPlus

07236dd218acc51812c47f92cd6bba19?s=128

yashigani

April 15, 2015
Tweet

Transcript

  1. 8,8FC7JFXΛ γϡοͱ࢖͏ @yashigani potatotips #16

  2. yashigani id:yashigani_w @yashigani Mobile Application Engineer http://yashigani.hatenablog.com Hatena

  3. 8,8FC7JFX

  4. 6*8FC7JFXJTEFBE -POHMJWF8,8FC7JFX ʕ.BUUU5IPNQTPO /4)JQTUFS

  5. ෆຬ

  6. target="_blank"໰୊ • func webView(_:createWebViewWithConfiguration:
 forNavigationAction:windowFeatures:) -> WKWebView! • ৽͘͠։͘WKWebViewΛ࡞ͬͯฦ͢ •

    nilΛฦͯ͠΋ͦͷWebViewͰ͸ϩʔυ͠ͳ͍
  7. func webView(webView: WKWebView, createWebViewWithConfiguration: WKWebViewConfiguration, forNavigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) ->

    WKWebView? { let request = forNavigationAction.request webView.loadRequest(request) return nil }
  8. alertͷදࣔ • alert, confirm, prompt • js͔Βͷཁٻʹ߹ΘͤͯΞϥʔτΛදࣔ͢Δ • ok, ok/cancel,

    textfield • ΄ͱΜͲఆܗ
  9. R.I.P. KVO • KVOͰ͖ΔϓϩύςΟ͕૿͑ͨ͜ͱࣗମ͸͏Ε͍͠ • swift࣌୅ʹ͓͍ͯ͸ॻ͖ͨ͘ͳ͍ • closureͰobserveͤͯ͞ཉ͍͠

  10. storyboardʹஔ͚ͳ͍ • IBͷObject libraryʹWKWebView͸ແ͍ • storyboardͱίʔυΛ૊Έ߹ΘͤͨΓɼίʔυͷΈ Ͱ࣮૷͢Δඞཁ • WebViewग़͍͚ͨͩ͠ɼΈ͍ͨͳը໘ʹ͸
 ͞΄ͲίετΛ͔͚ͨ͘ͳ͍

  11. https://flic.kr/p/5beGnc શવγϡοͱͯ͠ͳ͍

  12. 8FC,JU1MVT IUUQTHJUIVCDPNZBTIJHBOJ8FC,JU1MVT

  13. • WKWebViewͷ͔Ώ͍ͱ͜ΖΛཱͪͲ͜Ζʹղܾ • Carthage/CocoaPodsͰಋೖͰ͖Δ

  14. 8,6*%FMFHBUF1MVT

  15. • target=“_blank”ͷϫʔΫΞϥ΢ϯυΛ࣮૷ • ΋ͪΖΜ৔߹ʹΑͬͯผͷWKWebViewʹ
 ࠩ͠ସ͑Δ͜ͱ΋Մೳ • alert/confirm/promptͷॲཧΛ࣮૷

  16. lazy var UIDelegate = WKUIDelegatePlus(self) override public func viewDidLoad() {

    super.viewDidLoad() webView.UIDelegate = UIDelegate }
  17. 8FC7JFX0CTFSWFS

  18. • WKWebViewͷKVO compliantͳpropertyΛɼ closureͰobserveͰ͖ΔΑ͏ʹαϙʔτ

  19. lazy var observer = WebViewObserver(self.webView) override public func viewDidLoad() {

    super.viewDidLoad() observer.onTitleChanged = { [weak self] in self?.title = $0 } observer.onProgressChanged = { [weak self] in self?.progressbar.progress = $0 } }
  20. ;FO8FC7JFX$POUSPMMFS

  21. • WKWebViewΛ࣋ͬͨView Controller • Zen = “ષ” • WKWebViewૢ࡞ͷͨΊͷIBAction •

    goBack/goForward/reload/stopLoading • WKUIDelegatePlus, WebViewObserverΛ࣮૷ • storyboard͔Β࢖͑Δͧʂʂʂ
  22. 8FC,JU1MVTͰ 8,8FC7JFXΛγϡοͱ ࢖͓͏

  23. ͋Γ͕ͱ͏͍͟͝·ͨ͠