Skip to content

Instantly share code, notes, and snippets.

@iamazhar
Created March 7, 2019 19:10
Show Gist options
  • Select an option

  • Save iamazhar/048bf972e178743a02797ebd6e870579 to your computer and use it in GitHub Desktop.

Select an option

Save iamazhar/048bf972e178743a02797ebd6e870579 to your computer and use it in GitHub Desktop.
func displayContent(urlString: String) -> Void {
guard let url = URL(string: urlString) else{return}
let hideScriptURL = Bundle.main.path(forResource: "hideSections", ofType: "js")
do{
//Remove Content Blocks
let scriptContent = try String(contentsOfFile: hideScriptURL!, encoding: String.Encoding.utf8)
let hideSectionsScript = WKUserScript(source: scriptContent, injectionTime: .atDocumentStart, forMainFrameOnly: true)
let controller = WKUserContentController()
controller.addUserScript(hideSectionsScript)
let config = WKWebViewConfiguration()
config.userContentController = controller
//Set up WKWebView
nativeWebView = WKWebView(frame: self.view.frame, configuration: config)
nativeWebView.allowsBackForwardNavigationGestures = false
nativeWebView.scrollView.bounces = false
self.view.addSubview(nativeWebView)
//Load URL in WKWebView
nativeWebView.load(URLRequest(url: url))
//Initialize UI Elements
self.Activity.type = .circleStrokeSpin
self.Activity.color = UIColor(red: 20/255, green: 20/255, blue: 20/255, alpha: 1.0)
self.nativeWebView.addSubview(self.overlayImage)
self.nativeWebView.addSubview(self.Activity)
self.Activity.startAnimating()
self.nativeWebView.navigationDelegate = self
} catch{
print("Error")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment