Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
自社コンテンツ配信 のためのWebView Tips
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Shinji Kobayashi
April 28, 2017
Programming
5.6k
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
470
実践Protocol-Extension
gentlesoft
0
84
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
50
SwiftでUIKitDynamics
gentlesoft
0
59
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
630
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
700
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
490
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
220
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
360
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
4.2k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
260
継続モナドとリアクティブプログラミング
yukikurage
3
590
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
330
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
Featured
See All Featured
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Testing 201, or: Great Expectations
jmmastey
46
8.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
650
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
390
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
950
WCS-LA-2024
lcolladotor
0
710
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
200
The World Runs on Bad Software
bkeepers
PRO
72
12k
Navigating Team Friction
lara
192
16k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
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ػೳઃఆ๛ͳͷͰɺΧελϚΠ ζ࣍ୈͰ৭ʑͰ͖·͢ •ϋϚΓͲ͜Ζ͍ͬͺ͍͋ΔͷͰɺҙͯͬ͠ ͍͖ͯ·͠ΐ͏ •ϋϚͬͨΒͲ͔͜Ͱڞ༗ͯ͘͠ΕΔͱتͼ·͢