Skip to content

Commit adb197a

Browse files
committed
try custom viewcontroller to prevent ios stupidity
1 parent 3a88ee2 commit adb197a

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

.github/workflows/make-rel-ios.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
xcrun safari-web-extension-converter . --ios-only --force --no-prompt --no-open --bundle-identifier me.octonezd.oldlander
4343
export OL_VERSION=${{steps.manifest.outputs.version}}
4444
cat ../dev/ios/index.html | envsubst > OldLander/OldLander/Base.lproj/Main.html
45+
sed -i 's/MARKETING_VERSION = 1.0;/MARKETING_VERSION = ${{steps.manifest.outputs.version}};/g' OldLander/OldLander.xcodeproj/project.pbxproj
46+
cp ../dev/ios/ViewController.swift OldLander/OldLander/
4547
- name: Build ipa
4648
working-directory: ./dist/OldLander
4749
run: |

dev/ios/ViewController.swift

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// ViewController.swift
3+
// OldLander
4+
//
5+
// Created by runner on 1/3/24.
6+
//
7+
8+
import UIKit
9+
import WebKit
10+
11+
class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {
12+
13+
@IBOutlet var webView: WKWebView!
14+
15+
override func viewDidLoad() {
16+
super.viewDidLoad()
17+
18+
self.webView.navigationDelegate = self
19+
self.webView.scrollView.isScrollEnabled = false
20+
21+
self.webView.configuration.userContentController.add(self, name: "controller")
22+
23+
self.webView.loadFileURL(Bundle.main.url(forResource: "Main", withExtension: "html")!, allowingReadAccessTo: Bundle.main.resourceURL!)
24+
}
25+
26+
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
27+
// Override point for customization.
28+
}
29+
30+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
31+
// Override point for customization.
32+
}
33+
34+
// https://stackoverflow.com/a/64909961
35+
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
36+
guard case .linkActivated = navigationAction.navigationType,
37+
let url = navigationAction.request.url
38+
else {
39+
decisionHandler(.allow)
40+
return
41+
}
42+
decisionHandler(.cancel)
43+
UIApplication.shared.openURL(url)
44+
}
45+
46+
}

0 commit comments

Comments
 (0)