Skip to content

Commit

Permalink
try custom viewcontroller to prevent ios stupidity
Browse files Browse the repository at this point in the history
  • Loading branch information
OctoNezd committed Mar 20, 2024
1 parent 3a88ee2 commit adb197a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/make-rel-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
xcrun safari-web-extension-converter . --ios-only --force --no-prompt --no-open --bundle-identifier me.octonezd.oldlander
export OL_VERSION=${{steps.manifest.outputs.version}}
cat ../dev/ios/index.html | envsubst > OldLander/OldLander/Base.lproj/Main.html
sed -i 's/MARKETING_VERSION = 1.0;/MARKETING_VERSION = ${{steps.manifest.outputs.version}};/g' OldLander/OldLander.xcodeproj/project.pbxproj
cp ../dev/ios/ViewController.swift OldLander/OldLander/
- name: Build ipa
working-directory: ./dist/OldLander
run: |
Expand Down
46 changes: 46 additions & 0 deletions dev/ios/ViewController.swift
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)
}

}

0 comments on commit adb197a

Please sign in to comment.