Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自社コンテンツ配信 のためのWebView Tips
Search
Shinji Kobayashi
April 28, 2017
Programming
5.7k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自社コンテンツ配信 のためのWebView Tips
Swift愛好会 vol18
Shinji Kobayashi
April 28, 2017
More Decks by Shinji Kobayashi
See All by Shinji Kobayashi
5分でできる UITableViewのDrag & Drop
gentlesoft
0
480
実践Protocol-Extension
gentlesoft
0
86
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
53
SwiftでUIKitDynamics
gentlesoft
0
60
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
150
Kubernetes祭り #2 OP/ED
bells17
0
100
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
140
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
350
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
210
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
140
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
320
Rでドレミ/Do-Re-Mi_with_R
florets1
0
130
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
Simple Storage Service(S3) is not simple
iwatsukayura
0
220
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
GitHub's CSS Performance
jonrohan
1033
470k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
350
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.9k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Embracing the Ebb and Flow
colly
88
5.2k
ラッコキーワード サービス紹介資料
rakko
1
5.2M
Transcript
ࣗࣾίϯςϯπ৴ ͷͨΊͷWebView Tips Shinji Kobayashi TOPLOG / Gentlesoft SwiftѪձ vol18
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net ดத ετΞআ
Work https://toplog.jp/ TOPLOG iOS Engineer
TOPLOG ࣗࣾͰاըʗ࡞͍ͯ͠Δɺ ΞϓϦʹ࠷దԽͨ͠ϑΝογϣϯهࣄΛ৴
TOPICS • දࣔͷ֦େʗԡ͠ͷϝχϡʔͳͲΛېࢭ ͍ͨ͠ • ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ • ಈըΛࣗಈ࠶ੜ͍ͨ͠ • ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠
• ಛघͳϦϯΫΛઃఆͯ͠ΞϓϦʹಛఆͷಈ ࡞Λ͍ͤͨ͞
TOPICS • දࣔͷ֦େʗԡ͠ͷϝχϡʔͳͲΛېࢭ ͍ͨ͠ • ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ • ಈըΛࣗಈ࠶ੜ͍ͨ͠ • ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠
• ಛघͳϦϯΫΛઃఆͯ͠ΞϓϦʹಛఆͷಈ ࡞Λ͍ͤͨ͞
// બېࢭ͢ΔCSS let css = "body{-webkit-user-select:none;-webkit-user-drag:none;- webkit-touch-callout: none;}" // CSSΛಡΈࠐΜͩHTMLʹద༻͢Δjavascript
let js = "var style = document.createElement('style');" + "style.type = 'text/css';" + "var cssContent = document.createTextNode('\(css)');" + "style.appendChild(cssContent);" + "document.body.appendChild(style);" // javascriptΛϖʔδಡΈࠐΈྃ࣌ʹຖճ࣮ߦ͢ΔΑ͏ઃఆ let noneSelectScript = WKUserScript(source: js, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: false) //WebView࡞ let config = WKWebViewConfiguration() config.userContentController.addUserScript(noneSelectScript) let webView = WKWebView.init(frame: rect, configuration: config) දࣔͷ֦େʗԡ͠ͷϝχϡʔ Λېࢭ͍ͨ͠
// બېࢭ͢ΔCSS let css = "body{-webkit-user-select:none;-webkit-user-drag:none;- webkit-touch-callout: none;}" // CSSΛಡΈࠐΜͩHTMLʹద༻͢Δjavascript
let js = "var style = document.createElement('style');" + "style.type = 'text/css';" + "var cssContent = document.createTextNode('\(css)');" + "style.appendChild(cssContent);" + "document.body.appendChild(style);" // javascriptΛϖʔδಡΈࠐΈྃ࣌ʹຖճ࣮ߦ͢ΔΑ͏ઃఆ let noneSelectScript = WKUserScript(source: js, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: false) //WebView࡞ let config = WKWebViewConfiguration() config.userContentController.addUserScript(noneSelectScript) let webView = WKWebView.init(frame: rect, configuration: config) දࣔͷ֦େʗԡ͠ͷϝχϡʔ Λېࢭ͍ͨ͠ HTMLʹCSS Λࢦఆͯ͠ྑ͍
// બېࢭ͢ΔCSS let css = "body{-webkit-user-select:none;-webkit-user-drag:none;- webkit-touch-callout: none;}" // CSSΛಡΈࠐΜͩHTMLʹద༻͢Δjavascript
let js = "var style = document.createElement('style');" + "style.type = 'text/css';" + "var cssContent = document.createTextNode('\(css)');" + "style.appendChild(cssContent);" + "document.body.appendChild(style);" // javascriptΛϖʔδಡΈࠐΈྃ࣌ʹຖճ࣮ߦ͢ΔΑ͏ઃఆ let noneSelectScript = WKUserScript(source: js, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: false) //WebView࡞ let config = WKWebViewConfiguration() config.userContentController.addUserScript(noneSelectScript) let webView = WKWebView.init(frame: rect, configuration: config) දࣔͷ֦େʗԡ͠ͷϝχϡʔ Λېࢭ͍ͨ͠
// બېࢭ͢ΔCSS let css = "body{-webkit-user-select:none;-webkit-user-drag:none;- webkit-touch-callout: none;}" // CSSΛಡΈࠐΜͩHTMLʹద༻͢Δjavascript
let js = "var style = document.createElement('style');" + "style.type = 'text/css';" + "var cssContent = document.createTextNode('\(css)');" + "style.appendChild(cssContent);" + "document.body.appendChild(style);" // javascriptΛϖʔδಡΈࠐΈྃ࣌ʹຖճ࣮ߦ͢ΔΑ͏ઃఆ let noneSelectScript = WKUserScript(source: js, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: false) //WebView࡞ let config = WKWebViewConfiguration() config.userContentController.addUserScript(noneSelectScript) let webView = WKWebView.init(frame: rect, configuration: config) දࣔͷ֦େʗԡ͠ͷϝχϡʔ Λېࢭ͍ͨ͠
// બېࢭ͢ΔCSS let css = "body{-webkit-user-select:none;-webkit-user-drag:none;- webkit-touch-callout: none;}" // CSSΛಡΈࠐΜͩHTMLʹద༻͢Δjavascript
let js = "var style = document.createElement('style');" + "style.type = 'text/css';" + "var cssContent = document.createTextNode('\(css)');" + "style.appendChild(cssContent);" + "document.body.appendChild(style);" // javascriptΛϖʔδಡΈࠐΈྃ࣌ʹຖճ࣮ߦ͢ΔΑ͏ઃఆ let noneSelectScript = WKUserScript(source: js, injectionTime: WKUserScriptInjectionTime.atDocumentEnd, forMainFrameOnly: false) //WebView࡞ let config = WKWebViewConfiguration() config.userContentController.addUserScript(noneSelectScript) config.selectionGranularity = .character let webView = WKWebView.init(frame: rect, configuration: config) NG: දࣔͷ֦େʗԡ͠ͷϝχϡʔ Λېࢭ͍ͨ͠ ͜ͷࢦఆNG
TOPICS • දࣔͷ֦େʗԡ͠ͷϝχϡʔͳͲΛېࢭ ͍ͨ͠ • ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ • ಈըΛࣗಈ࠶ੜ͍ͨ͠ • ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠
• ಛघͳϦϯΫΛઃఆͯ͠ΞϓϦʹಛఆͷಈ ࡞Λ͍ͤͨ͞
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ //WebViewઃఆ let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true
config.userContentController.addUserScript(noneSelectScript) if #available(iOS 10.0, *) { config.mediaTypesRequiringUserActionForPlayback = [] } else { config.requiresUserActionForMediaPlayback = false } //WebView࡞ let config = WKWebViewConfiguration() let webView = WKWebView.init(frame: rect, configuration: config)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ //WebViewઃఆ let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true
config.userContentController.addUserScript(noneSelectScript) if #available(iOS 10.0, *) { config.mediaTypesRequiringUserActionForPlayback = [] } else { config.requiresUserActionForMediaPlayback = false } //WebView࡞ let config = WKWebViewConfiguration() let webView = WKWebView.init(frame: rect, configuration: config) ΠϯϥΠϯಈը࠶ੜΛڐՄ͢Δ
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ //WebViewઃఆ let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true
config.userContentController.addUserScript(noneSelectScript) if #available(iOS 10.0, *) { config.mediaTypesRequiringUserActionForPlayback = [] } else { config.requiresUserActionForMediaPlayback = false } //WebView࡞ let config = WKWebViewConfiguration() let webView = WKWebView.init(frame: rect, configuration: config) ࣗಈ࠶ੜΛڐՄ͢Δ (iOS ʙ9)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ //WebViewઃఆ let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback = true
config.userContentController.addUserScript(noneSelectScript) if #available(iOS 10.0, *) { config.mediaTypesRequiringUserActionForPlayback = [] } else { config.requiresUserActionForMediaPlayback = false } //WebView࡞ let config = WKWebViewConfiguration() let webView = WKWebView.init(frame: rect, configuration: config) ࣗಈ࠶ੜΛڐՄ͢Δ (iOS 10ʙ)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ <video src=“XXXXX.mp4” autoplay webkit-playsinline playsinline></video>
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ <video src=“XXXXX.mp4” autoplay webkit-playsinline playsinline></video> ࣗಈ࠶ੜͷઃఆ(PC, AndroidؚΉ)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ <video src=“XXXXX.mp4” autoplay webkit-playsinline playsinline></video> ΠϯϥΠϯ࠶ੜͷઃఆ(ʙiOS 9 WebViewͷΈ)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ ಈըΛࣗಈ࠶ੜ͍ͨ͠ <video src=“XXXXX.mp4” autoplay webkit-playsinline playsinline></video> ΠϯϥΠϯ࠶ੜͷઃఆ(iOS 10ʙ, WebView
/ Safari)
ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ NG: ಈըΛࣗಈ࠶ੜ͍ͨ͠ //WebViewઃఆ let config = WKWebViewConfiguration() config.allowsInlineMediaPlayback =
true config.userContentController.addUserScript(noneSelectScript) if #available(iOS 10.0, *) { config.mediaTypesRequiringUserActionForPlayback = [] } else { config.requiresUserActionForMediaPlayback = false } //WebView࡞ let config = WKWebViewConfiguration() let webView = WKWebView.init(frame: rect, configuration: config) ҰൠͷαΠτΛࢀর͢ΔWebViewʹ ઃఆ͠ͳ͍ํ͕ྑ͍
NG: ΠϯϥΠϯͰಈըΛ ࠶ੜͨ͠··ը໘ભҠ͢Δ
ը໘ભҠ͢Δલʹ࠶ੜதͷಈըΛ શͯఀࢭ͢Δ NG: ΠϯϥΠϯͰಈըΛ ࠶ੜͨ͠··ը໘ભҠ͢Δ
ը໘ભҠ͢Δલʹ࠶ੜதͷಈըΛ શͯఀࢭ͢Δ //࠶ੜதͷϜʔϏʔΛఀࢭ͢Δ func stopAllMovie() { let js = "var
v = document.getElementsByTagName('video');" + "for (var i = 0; i < v.length; ++i) { v[i].pause(); }" webView.evaluateJavaScript(js, completionHandler: nil) } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) self.stopAllMovie() }
TOPICS • දࣔͷ֦େʗԡ͠ͷϝχϡʔͳͲΛېࢭ ͍ͨ͠ • ಈըΛΠϯϥΠϯͰ࠶ੜ͍ͨ͠ • ಈըΛࣗಈ࠶ੜ͍ͨ͠ • ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠
• ಛघͳϦϯΫΛઃఆͯ͠ΞϓϦʹಛఆͷಈ ࡞Λ͍ͤͨ͞
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy)
-> Void) { var result = WKNavigationActionPolicy.cancel defer { decisionHandler(result) } guard let url = navigationAction.request.url else { return } if let info = TLConfig.getIndexUrlInfo(url.absoluteString) { // TOPLOGͷURLͰ͋Δ هࣄ༻ͷ7JFX$POUSPMMFSΛ࡞͠/BWJHBUJPO$POUSPMMFSʹPush } else { // ֎෦ͷ63-Ͱ͋Δ ผͷ8FC7JFXΛ࡞͠ϞʔμϧͰදࣔ } ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠
ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠ func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping
(WKNavigationActionPolicy) -> Void) { var result = WKNavigationActionPolicy.cancel defer { decisionHandler(result) } guard let url = navigationAction.request.url else { return } if let info = TLConfig.getIndexUrlInfo(url.absoluteString) { // TOPLOGͷURLͰ͋Δ هࣄ༻ͷ7JFX$POUSPMMFSΛ࡞͠/BWJHBUJPO$POUSPMMFSʹPush } else { // ֎෦ͷ63-Ͱ͋Δ ผͷ8FC7JFXΛ࡞͠ϞʔμϧͰදࣔ } WKNavigationDelegateͷ decidePolicyFornavigationActionΛ࣮ WebViewͷભҠΛϑοΫ͢Δ
ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠ func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping
(WKNavigationActionPolicy) -> Void) { var result = WKNavigationActionPolicy.cancel defer { decisionHandler(result) } guard let url = navigationAction.request.url else { return } if let info = TLConfig.getIndexUrlInfo(url.absoluteString) { // TOPLOGͷURLͰ͋Δ هࣄ༻ͷ7JFX$POUSPMMFSΛ࡞͠/BWJHBUJPO$POUSPMMFSʹPush } else { // ֎෦ͷ63-Ͱ͋Δ ผͷ8FC7JFXΛ࡞͠ϞʔμϧͰදࣔ } decisionHandlerʹWKNavigationActionPolicy.cancelΛ ηοτ͢ΔͱભҠ͠ͳ͍
ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠ func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping
(WKNavigationActionPolicy) -> Void) { var result = WKNavigationActionPolicy.cancel defer { decisionHandler(result) } guard let url = navigationAction.request.url else { return } if let info = TLConfig.getIndexUrlInfo(url.absoluteString) { // TOPLOGͷURLͰ͋Δ هࣄ༻ͷ7JFX$POUSPMMFSΛ࡞͠/BWJHBUJPO$POUSPMMFSʹPush } else { // ֎෦ͷ63-Ͱ͋Δ ผͷ8FC7JFXΛ࡞͠ϞʔμϧͰදࣔ } deferͰηοτ͓ͯ͘͠ͱguardͰఆͨ͠ޙʹ return͢Δ͚ͩͰྑ͍ͷͰॻ͖͍͢
ભҠઌʹΑͬͯը໘ͷಈ࡞Λมߋ͍ͨ͠ func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping
(WKNavigationActionPolicy) -> Void) { var result = WKNavigationActionPolicy.cancel defer { decisionHandler(result) } guard let url = navigationAction.request.url else { return } if let info = TLConfig.getIndexUrlInfo(url.absoluteString) { // TOPLOGͷURLͰ͋Δ هࣄ༻ͷ7JFX$POUSPMMFSΛ࡞͠/BWJHBUJPO$POUSPMMFSʹPush } else { // ֎෦ͷ63-Ͱ͋Δ ผͷ8FC7JFXΛ࡞͠ϞʔμϧͰදࣔ } URL͕ࣗࣾͷͷ͔Ͳ͏͔Λఆ
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ // ֎෦ͷ63-Ͱ͋Δ switch url.scheme! { case "safari-http": fallthrough
case "safari-https": let str = url.absoluteString guard let url = URL(string: str.substring(from: str.index(str.startIndex, offsetBy: "safari-".characters.count))) else { return } // Safariىಈ UIApplication.shared.openURL(url) case "http": fallthrough case "https": …
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ // ֎෦ͷ63-Ͱ͋Δ switch url.scheme! { case "safari-http": fallthrough
case "safari-https": let str = url.absoluteString guard let url = URL(string: str.substring(from: str.index(str.startIndex, offsetBy: "safari-".characters.count))) else { return } // Safariىಈ UIApplication.shared.openURL(url) case "http": fallthrough case "https": … SafariΛىಈ͢ΔಛघURL
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ // ֎෦ͷ63-Ͱ͋Δ switch url.scheme! { case "safari-http": fallthrough
case "safari-https": let str = url.absoluteString guard let url = URL(string: str.substring(from: str.index(str.startIndex, offsetBy: "safari-".characters.count))) else { return } // Safariىಈ UIApplication.shared.openURL(url) case "http": fallthrough case "https": … URL͔Βsafari-ΛऔΓআ͍ͯ OpenURLͰsafariΛىಈ
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": if navigationAction.targetFrame?.isMainFrame ??
false { // ϝΠϯը໘ͷભҠͷ߹ guard let host = url.host else { return } if directNavigationHosts.index(of: host) != nil { // ભҠ UIApplication.shared.openURL(url) } else { // ֎෦ࢀর༻ϒϥβΛϞʔμϧͰىಈ } } else { // ຒΊࠐΈͷ߹ result = WKNavigationActionPolicy.allow } …
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": if navigationAction.targetFrame?.isMainFrame ??
false { // ϝΠϯը໘ͷભҠͷ߹ guard let host = url.host else { return } if directNavigationHosts.index(of: host) != nil { // ભҠ UIApplication.shared.openURL(url) } else { // ֎෦ࢀর༻ϒϥβΛϞʔμϧͰىಈ } } else { // ຒΊࠐΈͷ߹ result = WKNavigationActionPolicy.allow } … ભҠ͢Δը໘͕ϝΠϯͷ ϑϨʔϜ͔Ͳ͏͔ΛνΣοΫ
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": if navigationAction.targetFrame?.isMainFrame ??
false { // ϝΠϯը໘ͷભҠͷ߹ guard let host = url.host else { return } if directNavigationHosts.index(of: host) != nil { // ભҠ UIApplication.shared.openURL(url) } else { // ֎෦ࢀর༻ϒϥβΛϞʔμϧͰىಈ } } else { // ຒΊࠐΈͷ߹ result = WKNavigationActionPolicy.allow } … ભҠ͍ͤͨ͞HostΛ ϦετΞοϓͯ͠ఆ (itunes.apple.comͳͲ)
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": if navigationAction.targetFrame?.isMainFrame ??
false { // ϝΠϯը໘ͷભҠͷ߹ guard let host = url.host else { return } if directNavigationHosts.index(of: host) != nil { // ભҠ UIApplication.shared.openURL(url) } else { // ֎෦ࢀর༻ϒϥβΛϞʔμϧͰىಈ } } else { // ຒΊࠐΈͷ߹ result = WKNavigationActionPolicy.allow } … SFSafariViewControllerผͷ֎෦ϒϥβ༻ ViewControllerΛϞʔμϧͰදࣔ
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": if navigationAction.targetFrame?.isMainFrame ??
false { // ϝΠϯը໘ͷભҠͷ߹ guard let host = url.host else { return } if directNavigationHosts.index(of: host) != nil { // ભҠ UIApplication.shared.openURL(url) } else { // ֎෦ࢀর༻ϒϥβΛϞʔμϧͰىಈ } } else { // ຒΊࠐΈͷ߹ result = WKNavigationActionPolicy.allow } … iFrameͳͲ
case "http": fallthrough case "https": … case "globalsetting-toplog": //ઃఆΛ։͘ case
"nextpage": //࣍ϖʔδ case "toplog-login": //ϩάΠϯ case "toplog-display-close": //Ϟʔμϧը໘Λด͡Δ … default: //֎෦ΞϓϦΛىಈ UIApplication.shared.openURL(url) } ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ ΞϓϦʹಈ࡞ΛϑΟʔυόοΫ
ಛघͳϦϯΫΛઃఆͯ͠ ΞϓϦʹಛఆͷಈ࡞Λ͍ͤͨ͞ case "http": fallthrough case "https": … case "globalsetting-toplog":
//ઃఆΛ։͘ case "nextpage": //࣍ϖʔδ case "toplog-login": //ϩάΠϯ case "toplog-display-close": //Ϟʔμϧը໘Λด͡Δ … default: //֎෦ΞϓϦΛىಈ UIApplication.shared.openURL(url) } ผΞϓϦͷURLεΩʔϜ
ࠓͤͳ͔ͬͨTOPICS • LINE SDKΛυΩϡϝϯτʹै࣮ͬͯͨ͠ ΒWebViewͰ͕ग़ͨ • WebViewͷcontentInsetͷ᠘ • WebViewͷϩʔυΛૣ͘ݟ͔͚ͤΔ
·ͱΊ •WebViewػೳઃఆ๛ͳͷͰɺΧελϚΠ ζ࣍ୈͰ৭ʑͰ͖·͢ •ϋϚΓͲ͜Ζ͍ͬͺ͍͋ΔͷͰɺҙͯͬ͠ ͍͖ͯ·͠ΐ͏ •ϋϚͬͨΒͲ͔͜Ͱڞ༗ͯ͘͠ΕΔͱتͼ·͢