Skip to content

Instantly share code, notes, and snippets.

@saitomarch
Created January 19, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saitomarch/786dfe963c883c04121ed0b224f8ce80 to your computer and use it in GitHub Desktop.
Save saitomarch/786dfe963c883c04121ed0b224f8ce80 to your computer and use it in GitHub Desktop.
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