不完全理解UIApplication.shared.canOpenUrl

Not fully understanding UIApplication.shared.canOpenUrl

想知道这在

中是如何实现的吗
appUrl = "http://dum:site2015@jobz.store.com/
if UIApplication.shared.canOpenURL(appUrl!){
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(appUrl!)
        }

在url方案中我有jobz-com

虽然我没有安装该应用程序,但事情正在变得真实......而是在 safari 中打开 url......但为什么没有变得错误,因为我没有安装了应用程序?

此功能不检查已安装的应用程序。它只是告诉您它是否可以在 safari 浏览器中或通过应用程序打开 URL。 有效的 URL 将始终 return 为真,因为系统实际上可以在某处打开它。

根据 Apple 自己的文档

A URL (Universal Resource Locator). At runtime, the system tests the URL’s scheme to determine if there is an installed app that is registered to handle the scheme. More than one app can be registered to handle a scheme. https://developer.apple.com/documentation/uikit/uiapplication/1622952-canopenurl

Safari 已注册以处理任何有效 URL,因此如果使用该方案的应用不存在,下一个注册读取它的应用程序是 safari。

我不认为有一个开放的 API 供您只在安装了该应用程序的情况下打开一个 URL。

并始终确保您的 URL 以您需要的方案开头,而不是 HTTP/S。 my-app://myurl/parameters

不要使用 http://https:// 打开应用程序。这些用于网站。使用这样的应用程序 url 方案:

jobz-com://

编辑

发问者试图实现的另一种方法是使用 Universal Link

这是 Apple's Official doc about Universal Links and you can follow this medium article 上面写着:

The workaround approach to deep linking with URI schemes involves using a traditional http:// link to launch a web browser. This link contains a JavaScript redirect to a custom URI scheme, which is executed by the web browser to launch the app. If the redirect attempt fails because the app is not installed, the JavaScript then takes the user to the App Store or Play Store.

Instead of opening up Safari first when a link is clicked, iOS will check if a Universal Link has been registered (an AASA (apple-app-site-association) file should be there in the domain which contains the bundle id of the app and the paths the app should open) for the domain associated with the link, then check if the corresponding app is installed. If the app is currently installed, it will be opened. If it’s not, Safari will open and the http(s) link will load.