iOS通用链接与通配符无法正常工作

时间:2023-01-23 13:03:14

In an iOS app I am working on I have setup Universal Links. The app hosts multiple domains. Some domains I have set up with a wildcard. These domains do not seem to work. For example, I want to link to https://news.mydomain.com/. If I add the following to the list of associated domains:

在我正在开发的iOS应用程序中,我设置了Universal Links。该应用程序托管多个域。我使用通配符设置了一些域名。这些域似乎不起作用。例如,我想链接到https://news.mydomain.com/。如果我将以下内容添加到关联域列表中:

applinks:*.mydomain.com -> Does not work

applinks:*。mydomain.com - >不起作用

applinks:news.mydomain.com -> works fine

applinks:news.mydomain.com - >工作正常

So I believe I did set up all correct, the apple-app-site-association file is setup fine. I can even see in both cases (using Charles Proxy) the apple-app-site-association file got retrieved ok.

所以我相信我确实设置正确,apple-app-site-association文件设置正常。我甚至可以在两种情况下(使用Charles Proxy)看到apple-app-site-association文件被检索好了。

In the case of the wildcard, the link only opens in Safari.

对于通配符,链接仅在Safari中打开。

When I configure the domain without a wildcard, the App opens.

当我在没有通配符的情况下配置域时,应用程序将打开。

Am I missing something here? I am running iOS 9.3.2 on the device and I am running Xcode 7.3.1 which are today the latest versions.

我在这里错过了什么吗?我在设备上运行iOS 9.3.2,我正在运行Xcode 7.3.1,它们是今天的最新版本。

4 个解决方案

#1


14  

I added my findings to this thread: https://forums.developer.apple.com/thread/47315

我将我的发现添加到这个主题:https://forums.developer.apple.com/thread/47315

In short, even in iOS 10, it appears that the wildcard setup requires that the apple-app-site-association file be served by the wildcard's root.

简而言之,即使在iOS 10中,通配符设置似乎要求通配符的根提供apple-app-site-association文件。

For instance, if you want to use *.domain.com, then the apple-app-site-association needs to be hosted at both, e.g., app1.domain.com and domain.com, else it won't work with simply specifying applinks:*.domain.com in Xcode.

例如,如果你想使用* .domain.com,那么apple-app-site-association需要托管在两者上,例如app1.domain.com和domain.com,否则它将无法简单地使用在Xcode中指定applinks:*。domain.com。

This is unfortunate if your main site is hosted at www.domain.com, and that you have a 301 redirect on domain.com (which redirects you to www.domain.com), because Universal Links do not allow redirects.

如果您的主站点在www.domain.com上托管,并且您在domain.com上有301重定向(将您重定向到www.domain.com),这是不幸的,因为Universal Links不允许重定向。

The workaround I found was to create a main subdomain for your app, and to use sub-subdomains for the wildcard. E.g.

我找到的解决方法是为您的应用创建一个主子域,并使用子子域作为通配符。例如。

  • app.domain.com (must serve the apple-app-site-association file)
  • app.domain.com(必须提供apple-app-site-association文件)

  • server1.app.domain.com (must serve the apple-app-site-association)
  • server1.app.domain.com(必须提供apple-app-site-association)

  • server2.app.domain.com (...)

That way, in Xcode, you may only specify applinks:*.app.domain.com and Universal Links will work without you having to specify server1.app.domain.com, server2.app.domain.com, and so on... in Xcode.

这样,在Xcode中,您只能指定applinks:*。app.domain.com和Universal Links将无需指定server1.app.domain.com,server2.app.domain.com等等。在Xcode中。

Note, however, that you must also explicitly specify applinks:app.domain.com if you plan on using that server as well with your app.

但请注意,如果您计划将该服务器与您的应用程序一起使用,则还必须明确指定applinks:app.domain.com。

I hope this helps.

我希望这有帮助。

#2


2  

It seems that adding a wildcard in the domain part of the applinks has only been introduced in iOS 9.3 Beta 2. In 9.3 Beta 2 release notes:

似乎在applinks的域部分中添加通配符仅在iOS 9.3 Beta 2中引入。在9.3 Beta 2发行说明中:

You can now use Universal Links with arbitrary subdomains instead of needing to list all of the app’s subdomains as fully qualified domain names. Entries have the form:

您现在可以将Universal Links与任意子域一起使用,而不需要将所有应用程序的子域列为完全限定的域名。参赛作品的形式如下:

:[:port number] in which is “webcredentials”, “activitycontinuation”, or “applinks”.

:[:端口号],其中包含“webcredentials”,“activitycontinuation”或“applinks”。

The part of the entry can now optionally be prefixed with “*.” to indicate a wildcard subdomain. For example:

现在,条目的一部分可以选择以“*。”作为前缀,以指示通配符子域。例如:

applinks:*.example.com

You say that you run on iOS 9.3.2. But is your deployment target >= iOS 9.3 ? If it's not: try by changing it. I think it will solve your issue.

你说你在iOS 9.3.2上运行。但是您的部署目标是> = iOS 9.3吗?如果不是:尝试改变它。我认为这将解决您的问题。

Here you can found a copy of this release notes (sorry, I do not have any other public source)

在这里你可以找到这个发行说明的副本(抱歉,我没有任何其他公共来源)

Edit:

Even if the Apple Doc say that you can use wildcards on domains, they seems to have an issue on this:

即使Apple Doc说您可以在域上使用通配符,它​​们似乎也存在问题:

To match all subdomains of an associated domain, you can specify a wildcard by prefixing . before the beginning of a specific domain (the period is required). Domain matching is based on the longest substring in the applinks entries. For example, if you specify the entries applinks:.mywebsite.com and applinks:*.users.mywebsite.com, matching for the domain emily.users.mywebsite.com is performed against the longer *.users.mywebsite.com entry. Note that an entry for *.mywebsite.com does not match mywebsite.com because of the period after the asterisk. To enable matching for both *.mywebsite.com and mywebsite.com, you need to provide a separate applinks entry for each.

要匹配关联域的所有子域,可以通过前缀指定通配符。在特定域开始之前(需要该期间)。域匹配基于applinks条目中最长的子字符串。例如,如果您指定条目applinks:.mywebsite.com和applinks:*。userss.mywebsite.com,则会针对较长的* .users.mywebsite.com条目执行域emily.users.mywebsite.com的匹配。请注意,由于星号后的句点,* .mywebsite.com的条目与mywebsite.com不匹配。要为* .mywebsite.com和mywebsite.com启用匹配,您需要为每个提供单独的applinks条目。

#3


1  

I think it is apple bug in documentation. I got same error on 9.3.1. And 9.3.2 works fine. Very interesting link, about signing problems, see Laurence Fan's comment

我认为这是文档中的苹果bug。我在9.3.1上遇到了同样的错误。并且9.3.2工作正常。非常有趣的链接,关于签署问题,请参阅Laurence Fan的评论

Apple should say that *.domain.com works for >= 9.3.2 in this link Support Universal Links

Apple应该说* .domain.com适用于> = 9.3.2在此链接支持通用链接

#4


1  

I tried this in Sept 2016, with both iOS 9.3.5 and iOS 10 beta. Situation appears unchanged: universal links are still not working if applinks contains only wildcard domains, even though the documentation suggests that this should work.

我在2016年9月尝试了这个,包括iOS 9.3.5和iOS 10 beta。情况似乎没有变化:如果applinks仅包含通配符域,则通用链接仍然无效,即使文档表明这应该有效。

#1


14  

I added my findings to this thread: https://forums.developer.apple.com/thread/47315

我将我的发现添加到这个主题:https://forums.developer.apple.com/thread/47315

In short, even in iOS 10, it appears that the wildcard setup requires that the apple-app-site-association file be served by the wildcard's root.

简而言之,即使在iOS 10中,通配符设置似乎要求通配符的根提供apple-app-site-association文件。

For instance, if you want to use *.domain.com, then the apple-app-site-association needs to be hosted at both, e.g., app1.domain.com and domain.com, else it won't work with simply specifying applinks:*.domain.com in Xcode.

例如,如果你想使用* .domain.com,那么apple-app-site-association需要托管在两者上,例如app1.domain.com和domain.com,否则它将无法简单地使用在Xcode中指定applinks:*。domain.com。

This is unfortunate if your main site is hosted at www.domain.com, and that you have a 301 redirect on domain.com (which redirects you to www.domain.com), because Universal Links do not allow redirects.

如果您的主站点在www.domain.com上托管,并且您在domain.com上有301重定向(将您重定向到www.domain.com),这是不幸的,因为Universal Links不允许重定向。

The workaround I found was to create a main subdomain for your app, and to use sub-subdomains for the wildcard. E.g.

我找到的解决方法是为您的应用创建一个主子域,并使用子子域作为通配符。例如。

  • app.domain.com (must serve the apple-app-site-association file)
  • app.domain.com(必须提供apple-app-site-association文件)

  • server1.app.domain.com (must serve the apple-app-site-association)
  • server1.app.domain.com(必须提供apple-app-site-association)

  • server2.app.domain.com (...)

That way, in Xcode, you may only specify applinks:*.app.domain.com and Universal Links will work without you having to specify server1.app.domain.com, server2.app.domain.com, and so on... in Xcode.

这样,在Xcode中,您只能指定applinks:*。app.domain.com和Universal Links将无需指定server1.app.domain.com,server2.app.domain.com等等。在Xcode中。

Note, however, that you must also explicitly specify applinks:app.domain.com if you plan on using that server as well with your app.

但请注意,如果您计划将该服务器与您的应用程序一起使用,则还必须明确指定applinks:app.domain.com。

I hope this helps.

我希望这有帮助。

#2


2  

It seems that adding a wildcard in the domain part of the applinks has only been introduced in iOS 9.3 Beta 2. In 9.3 Beta 2 release notes:

似乎在applinks的域部分中添加通配符仅在iOS 9.3 Beta 2中引入。在9.3 Beta 2发行说明中:

You can now use Universal Links with arbitrary subdomains instead of needing to list all of the app’s subdomains as fully qualified domain names. Entries have the form:

您现在可以将Universal Links与任意子域一起使用,而不需要将所有应用程序的子域列为完全限定的域名。参赛作品的形式如下:

:[:port number] in which is “webcredentials”, “activitycontinuation”, or “applinks”.

:[:端口号],其中包含“webcredentials”,“activitycontinuation”或“applinks”。

The part of the entry can now optionally be prefixed with “*.” to indicate a wildcard subdomain. For example:

现在,条目的一部分可以选择以“*。”作为前缀,以指示通配符子域。例如:

applinks:*.example.com

You say that you run on iOS 9.3.2. But is your deployment target >= iOS 9.3 ? If it's not: try by changing it. I think it will solve your issue.

你说你在iOS 9.3.2上运行。但是您的部署目标是> = iOS 9.3吗?如果不是:尝试改变它。我认为这将解决您的问题。

Here you can found a copy of this release notes (sorry, I do not have any other public source)

在这里你可以找到这个发行说明的副本(抱歉,我没有任何其他公共来源)

Edit:

Even if the Apple Doc say that you can use wildcards on domains, they seems to have an issue on this:

即使Apple Doc说您可以在域上使用通配符,它​​们似乎也存在问题:

To match all subdomains of an associated domain, you can specify a wildcard by prefixing . before the beginning of a specific domain (the period is required). Domain matching is based on the longest substring in the applinks entries. For example, if you specify the entries applinks:.mywebsite.com and applinks:*.users.mywebsite.com, matching for the domain emily.users.mywebsite.com is performed against the longer *.users.mywebsite.com entry. Note that an entry for *.mywebsite.com does not match mywebsite.com because of the period after the asterisk. To enable matching for both *.mywebsite.com and mywebsite.com, you need to provide a separate applinks entry for each.

要匹配关联域的所有子域,可以通过前缀指定通配符。在特定域开始之前(需要该期间)。域匹配基于applinks条目中最长的子字符串。例如,如果您指定条目applinks:.mywebsite.com和applinks:*。userss.mywebsite.com,则会针对较长的* .users.mywebsite.com条目执行域emily.users.mywebsite.com的匹配。请注意,由于星号后的句点,* .mywebsite.com的条目与mywebsite.com不匹配。要为* .mywebsite.com和mywebsite.com启用匹配,您需要为每个提供单独的applinks条目。

#3


1  

I think it is apple bug in documentation. I got same error on 9.3.1. And 9.3.2 works fine. Very interesting link, about signing problems, see Laurence Fan's comment

我认为这是文档中的苹果bug。我在9.3.1上遇到了同样的错误。并且9.3.2工作正常。非常有趣的链接,关于签署问题,请参阅Laurence Fan的评论

Apple should say that *.domain.com works for >= 9.3.2 in this link Support Universal Links

Apple应该说* .domain.com适用于> = 9.3.2在此链接支持通用链接

#4


1  

I tried this in Sept 2016, with both iOS 9.3.5 and iOS 10 beta. Situation appears unchanged: universal links are still not working if applinks contains only wildcard domains, even though the documentation suggests that this should work.

我在2016年9月尝试了这个,包括iOS 9.3.5和iOS 10 beta。情况似乎没有变化:如果applinks仅包含通配符域,则通用链接仍然无效,即使文档表明这应该有效。