如何使用UIApplication.shared.open在iOS上选择性地打开其他应用程序



我有一个允许用户打开URL的应用程序。这些可以通过SafariView处理,但如果应用程序已经注册来处理URL,我想使用:

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

然而,这似乎在打开Safari后有所回落。在这种情况下,我想在自己的应用程序中使用SafariView。是否可以选择性地选择使用哪些外部应用程序?

;universalLinksOnly";选项可以与检查完成处理程序是否为true一起使用。

if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [.universalLinksOnly: true], completionHandler: { wasHandled in
if !wasHandled {
handleExternalUrlWithSafariView(url)
}
})
} else {
handleExternalUrlWithSafariView(url)
}

其中";handleExternalUrlWithSafariView";是我定义的一个函数,用于打开具有给定URL的SafariView。

最新更新