Universal link 转到 Safari 而不是调用它的应用程序。

huangapple go评论59阅读模式
英文:

universal link goes to safari instead of the app that called it

问题

我有一个可以在其他应用中使用的工作通用链接。例如,如果我在记事本中写入该链接,它将打开该应用程序。但是当我在通用链接所链接的应用程序内部调用以下代码时,它将在Safari中打开。canOpenURL 返回true。

我已经设置了.well-known/apple-app-site-association,并且也设置了正确的intent-filter。我认为它是工作的,因为在应用程序外部点击链接时,会打开应用程序。

let url = Foundation.URL(string: "https://workingdeeplink.com/")!
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
英文:

I have a working universal link that works when used by another app. eg. if I write the link in notepad it will open app the app. But when I call the following inside the app that the universal link links to, it will open in safari. canOpenURL returns true.

have set up this .well-known/apple-app-site-association and also the correct intent-filter. I think its working because the links open the app when clicked outside of the app.

let url = Foundation.URL(string: "https://workingdeeplink.com/")!
        if UIApplication.shared.canOpenURL(url) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }

答案1

得分: 3

这是预期行为。当应用程序将其自己的通用链接传递给open时,iOS会在Safari中打开该链接。

这样做的目的是为了在应用程序无法处理传入链接时提供备用选项。处理传入链接的逻辑通常如下:

  1. 解析传入链接
  2. 确定应用程序是否能够处理它
  3. 如果可以处理,那么处理链接(例如,选择特定视图或执行某些操作)
  4. 如果不能处理,将链接传递给open,以便用户被重定向回网站,其中链接可以被处理。

这样可以避免深度链接打开您的应用程序然后什么都不发生或显示错误(因为应用程序无法处理该URL)。

不应该出现这样的情况,即您的应用程序尝试open它可以处理的深度链接;它可以直接绕过整个深度链接处理过程并执行直接产生的操作。

英文:

This is expected behaviour. When an app passes its own universal link to open, iOS will open that link in Safari.

The purpose of this is to allow a fallback when an app cannot handle an incoming link. The logic for handling an incoming link is typically something like:

  1. Parse the incoming link
  2. Determine if the app can handle it
  3. If it can, then handle the link (e.g. select a specific view or take some action)
  4. If it can't, pass the link to open so that the user is redirected back to the web site, where the link can be handled.

This avoids the situation where a deep link opens your app and then nothing happens or an error is shown (because the app can't handle the url)

There shouldn't be a case where your app tries to open a deep link it can handle; it can simply bypass then whole deep link process and take the action that would result directly.

答案2

得分: 1

在我的情况下,问题发生在文件 .well-known/apple-app-site-association(AASA)未被下载的情况下。

苹果文档表示:(https://developer.apple.com/documentation/xcode/supporting-associated-domains):

当用户安装您的应用时,系统会尝试下载关联域文件并验证您在权限中的域。

似乎有时由于某种原因文件未被下载。您可以使用MAC控制台应用程序验证AASA文件是否成功下载,并通过“swcd”进程(共享网络凭据守护程序)过滤控制台输出。

如果AASA成功下载,您将看到swcd进程的活动。如果AASA未下载,您必须卸载应用程序,重新启动设备,然后重新安装应用程序(在我的情况下,我多次卸载了应用程序)。

在这里找到详细的说明:https://help.branch.io/developers-hub/docs/ios-troubleshooting#validate-if-aasa-file-successfully-downloaded

英文:

In my case the problem occurred because file .well-known/apple-app-site-association (AASA) was not downloaded.

Apple documentation says: (https://developer.apple.com/documentation/xcode/supporting-associated-domains):

> When a user installs your app, the system attempts to download the
> associated domain file and verify the domains in your entitlement.

It seems sometimes the file isn't dowloaded for any reason. You can validate if AASA file was successfully downloaded using MAC Console app and filtering console output by "swcd" process (shared web credential daemon).

If the AASA downloaded sucessfully, you'll see activities of swcd process. If the AASA did not download, you must uninstall the app, restart the device, and then reinstall the app (in my case I uninstalled app for several times).

Find the detailed instructions here: https://help.branch.io/developers-hub/docs/ios-troubleshooting#validate-if-aasa-file-successfully-downloaded

huangapple
  • 本文由 发表于 2023年2月16日 04:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464958.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定