【发布时间】:2019-12-20 10:13:42
【问题描述】:
我在 Swift 4 中创建了一个自制的 PWA 应用程序来浏览我的网站,其中包含一些选项,例如 Firebase 和 Notifies
当我的网站在 Safari 中打开或用户单击朋友共享的通用链接时,我需要打开我的应用程序。
我使用apple-app-site-association 正确设置了我的网站,并且它可以正常工作,当我在 Safari 中打开相关网址时,它会向我显示打开我的应用程序的提示。
但问题是,当我在 Safari 中出现提示之间打开我的应用程序时尝试处理通用链接时,我尝试使用它(正如 Apple 文档所说的 universal-link)
func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool{
要更改我的 WKWebView,我使用了基于 this 答案的代码。
这是我在 func continue 中的 AppDelegate 代码,用于更改 WebView url:
if(userActivity.webpageURL != nil){
g_url = userActivity.webpageURL // g_url is declared at top as 'var g_url: URL?'
let notificationName = NSNotification.Name(rawValue: "updateUrl")
NotificationCenter.default.post(name: notificationName, object: nil)
return true
}else{
return false
}
这是在 ViewController 中设置 url 的代码:
let appDelegate = UIApplication.shared.delegate as! AppDelegate
url = appDelegate.g_url
let notificationName = Notification.Name("updateUrl")
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.updateUrl), name: notificationName, object: nil)
updateUrl()
更新网址:
@objc func updateUrl(){
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if(appDelegate.g_url != nil){
url = appDelegate.g_url!
}else{
url = URL(string: "https://my.Site/Home")!
}
let request = URLRequest(url: url)
MyWebView.load(request)
MyWebView.navigationDelegate = self
当 Safari 调用应用程序时,WebView 页面是最后一个打开的页面,如果是第一次打开,则为“主页”。
我需要了解我是否遗漏了什么,或者我是否应该使用其他东西来制作这个
【问题讨论】:
标签: ios swift4 wkwebview xcode11 ios-universal-links