-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try custom viewcontroller to prevent ios stupidity
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// ViewController.swift | ||
// OldLander | ||
// | ||
// Created by runner on 1/3/24. | ||
// | ||
|
||
import UIKit | ||
import WebKit | ||
|
||
class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler { | ||
|
||
@IBOutlet var webView: WKWebView! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.webView.navigationDelegate = self | ||
self.webView.scrollView.isScrollEnabled = false | ||
|
||
self.webView.configuration.userContentController.add(self, name: "controller") | ||
|
||
self.webView.loadFileURL(Bundle.main.url(forResource: "Main", withExtension: "html")!, allowingReadAccessTo: Bundle.main.resourceURL!) | ||
} | ||
|
||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { | ||
// Override point for customization. | ||
} | ||
|
||
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { | ||
// Override point for customization. | ||
} | ||
|
||
// https://stackoverflow.com/a/64909961 | ||
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { | ||
guard case .linkActivated = navigationAction.navigationType, | ||
let url = navigationAction.request.url | ||
else { | ||
decisionHandler(.allow) | ||
return | ||
} | ||
decisionHandler(.cancel) | ||
UIApplication.shared.openURL(url) | ||
} | ||
|
||
} |