Skip to content

Instantly share code, notes, and snippets.

@saitomarch
Created January 19, 2017 09:09
Embed
What would you like to do?
WKWebView JavaScript Injection to block zoom.
// Remember to import WebKit at the top of the file
let source = "var meta = document.createElement('meta');" +
"meta.name = 'viewport';" +
"meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';" +
"var head = document.getElementsByTagName('head')[0];" +
"head.appendChild(meta);"
let userContentController = WKUserContentController()
userContentController.addUserScript(script)
let configuration = WKWebViewConfiguration()
configuration.userContentController = userContentController
let webview = WKWebView(frame: .zero, configuration: configuration)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment