当应用程序关闭时,iOS Widget的Deep Link吗? [英] iOS Deep Link from Widget when App closed?
本文介绍了当应用程序关闭时,iOS Widget的Deep Link吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的窗口小部件具有几个用户可以单击的链接,这些链接的设置如下:
My widget has several links that the user can click, the link are set up as follows:
Link(destination: URL(string: "widget://start")!)
现在,我可以使用以下功能检测场景委托中的按下情况:
Now I am able to detect the press in the scene delegate with the following function:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let item = URLContexts.first {
UserDefaults.standard.set(item.url.absoluteString, forKey: "URL")
print(item.url)
print(URLContexts)
}
}
但是,当应用程序关闭时,这不起作用.我尝试将这段代码放在场景委托,应用程序委托的任何地方,但是我找不到在关闭应用程序时如何检测点击的解决方案.有办法吗?
However, that doesn't work when the app is closed. I tried putting this block of code everywhere, scene delegate, app delegate, but I just can't find a solution on how to detect the tap when the app is closed. Is there a way to do that?
推荐答案
添加此
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
if let item = connectionOptions.urlContexts.first {
UserDefaults.standard.set(item.url.absoluteString, forKey: "URL")
print(item.url)
print(URLContexts)
}
}
}
这篇关于当应用程序关闭时,iOS Widget的Deep Link吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文