126 lines
3 KiB
Swift
126 lines
3 KiB
Swift
//
|
|
// WebView.swift
|
|
// TheSwiftWeek
|
|
//
|
|
// Created by Ingo Rohlf on 23.10.25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
import WebKit
|
|
import SafariServices
|
|
|
|
struct LoadingWebView: View {
|
|
@State private var isLoading = true
|
|
|
|
var body: some View {
|
|
ZStack {
|
|
if #available(iOS 26.0, *) {
|
|
WebGitView { isLoading = false }
|
|
} else {
|
|
// Fallback on earlier versions
|
|
}
|
|
if isLoading { ProgressView() }
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
struct WebAppView: View {
|
|
// @State private var page = WebPage()
|
|
|
|
|
|
var body: some View {
|
|
|
|
if let url = URL(string: "https://minecraft.irohlf.de") {
|
|
|
|
if #available(iOS 26.0, *) {
|
|
Text("WebView für iOS 26+")
|
|
WebGitView{
|
|
|
|
}
|
|
|
|
} else {
|
|
Text("please update to iOS 26.0 or later")
|
|
// WebOldView(url: URL(string: "https://ai.irohlf.de")!)
|
|
SafariView(url: URL(string: "https://cloud.irohlf.de/s/oWYjxWJN9WwJsWq")!)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@available(iOS 26.0, *)
|
|
struct WebGitView: UIViewRepresentable {
|
|
|
|
|
|
func makeCoordinator() -> Coordinator {
|
|
Coordinator(parent: self)
|
|
}
|
|
let url: URL = URL(string: "https://git.irohlf.de")!
|
|
var completion: () -> Void
|
|
|
|
//typealias UIViewType = WKWebView
|
|
func makeUIView(context: Context) -> WKWebView {
|
|
let webView = WKWebView()
|
|
webView.navigationDelegate = context.coordinator
|
|
return webView
|
|
}
|
|
|
|
|
|
func updateUIView(_ uiView: WKWebView, context: Context) {
|
|
uiView.load(URLRequest(url: url))
|
|
}
|
|
|
|
@available(iOS 26.0, *)
|
|
class Coordinator: NSObject, WKNavigationDelegate {
|
|
var parent: WebGitView
|
|
init(parent: WebGitView ) {
|
|
self.parent = parent
|
|
}
|
|
|
|
|
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
print("Fertsch geladen")
|
|
}
|
|
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
|
|
print("Bin laden")
|
|
}
|
|
|
|
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
struct WebOldView: UIViewRepresentable {
|
|
let url: URL
|
|
//typealias UIViewType = WKWebView
|
|
func makeUIView(context: Context) -> WKWebView {
|
|
.init()
|
|
}
|
|
func updateUIView(_ uiView: WKWebView, context: Context) {
|
|
uiView.load(URLRequest(url: url))
|
|
}
|
|
|
|
}
|
|
|
|
struct SafariView: UIViewControllerRepresentable {
|
|
|
|
let url: URL
|
|
/// typealias UIViewControllerType = SFSafariViewController
|
|
|
|
func makeUIViewController(context: Context) -> SFSafariViewController {
|
|
.init(url: url)
|
|
}
|
|
func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
LoadingWebView()
|
|
}
|