I'm currently trying to wrap a rails app in a webview so I can get native push notification functionality. I'm having troubles trying to figure out how to get javascript confirm and alerts working when using swiftui.
Heres what I got so far:
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
WebView().edgesIgnoringSafeArea(.all)
}
}
struct WebView: UIViewRepresentable {
func makeUIView(context: Context) -> WKWebView {
let webView = WKWebView()
return webView
}
func updateUIView(_ webView: WKWebView, context: Context) {
let appUrl = "http://localhost:3000"
if let url = URL(string: appUrl) {
let request = URLRequest(url: url)
webView.load(request)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
This works loading the app, everything appears to work fine except alerts and confirm dialogs.
I ended up going with https://github.com/lazaronixon/react-native-turbolinks . At least now I can just use javascript rather than learning swift and kotlin/java.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.