我需要pushwoosh sdk仍然是AppDelegate ...在appdelegate中-我如何访问webview并更改url(取决于从appdelegate收到的推送通知?pushnotifications并且一切正常...初始网页也在启动时加载。但是我如何在应用程序委托中更改 url?
主应用:
@main
struct XYApp: App {
@UIApplicationDelegateAdaptor var delegate: FSAppDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class FSAppDelegate: UIResponder, UIApplicationDelegate, PWMessagingDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//initialization code
//set custom delegate for push handling, in our case AppDelegate
Pushwoosh.sharedInstance()?.delegate = self;
//register for push notifications
Pushwoosh.sharedInstance()?.registerForPushNotifications()
print("token: ",Pushwoosh.sharedInstance()?.getPushToken())
return true
}
}
快速查看
import SwiftUI
struct ContentView: View {
@State private var showWebView = false
var body: some View {
WebView(url: URL(string: "https://www.xy.com/mobile")!)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
快速浏览网页
import SwiftUI
import WebKit
struct WebView: UIViewRepresentable {
var url: URL
func makeUIView(context: Context) -> WKWebView {
return WKWebView()
}
func updateUIView(_ webView: WKWebView, context: Context) {
let request = URLRequest(url: url)
webView.load(request)
}
}