为通用链接配置 Xamarin.Forms iOS 应用程序?

Configure Xamarin.Forms iOS app for Universal Links?

我正在按照这些说明进行操作。该应用程序是 Xamarin.Forms iOS 应用程序。

https://xamarinhelp.com/ios-universal-links/

这是我不确定的地方。

首先,我将 well-known 文件夹添加到我的 MVC 5 Web 应用程序。我无法添加 .well-known 文件夹。因为我无法添加“。”在文件夹前面,我使用Azure Portal添加了一个虚拟目录。

当我尝试使用 https://portal.mydomain.com/.well-known/apple-app-site-association 访问文件时,我收到以下消息。

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

其次,我不得不使用 XML 文本编辑器编辑 Entitlements.plist。这是我的条目的样子。

<plist version="1.0">
 <dict>
  <key>com.apple.developer.associated-domains</key>
  <array>
    <string>applinks: portal.mydomain.com</string>
    <!--<string>your domain</string>-->
  </array>
 </dict>
</plist>

接下来,这是 ContinueUserActivity 和 OpenUrl 的样子。

//AppLinks应用运行

public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
    {
        try
        {

            if (userActivity.ActivityType == "NSUserActivityTypeBrowsingWeb")
            {
                if (userActivity.WebPageUrl.AbsoluteString.Contains("/PublicOffers/OffersPage"))
                {

                    ((App)Xamarin.Forms.Application.Current).AppLinkRequest(new
                    Uri(userActivity.WebPageUrl.AbsoluteString));
                    return true;
                }

            }

        }
        catch
        {
            // Ignore issue for now
        }

        return base.ContinueUserActivity(application, userActivity, completionHandler);
    }

//AppLinks应用不是运行

public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
    {

        try
        {
            var components = new NSUrlComponents(url, true);
            var path = components.Path;
            var query = components.Query;

            // Is this a known format?
            if (path == "/PublicOffers/OffersPage")
            {
                // Send to App.xaml.cs
                ((App)Xamarin.Forms.Application.Current).AppLinkRequest(new
                Uri(url.AbsoluteString));
                return true;
            }
        }
        catch
        {
            // Ignore issue for now
        }

        //return false;

        return base.OpenUrl(app, url, options);
    }

最后,我创建了调用 OnAppLinkRequestReceived 的方法。

public async void AppLinkRequest(Uri uri)
    {
        OnAppLinkRequestReceived(uri);
    }

问题是 ContinueUserActivity 和 OpenUrl 永远不会被调用。

这里是 Url 我想 open/prompt 使用通用链接的应用程序的示例。

https://portal.mydomain.com/PublicOffers/OffersPage?id=SOMEGUID&cid=SOMEGUID

非常感谢任何想法、帮助或建议。谢谢!

更新 1

我在我的 well-known 文件夹中添加了一个新的 web.config 文件,并像这样配置它。我现在可以访问这两个文件。不过,我的 iOS 通用链接仍然无法使用。

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
 <system.webServer>
  <staticContent>
   <mimeMap fileExtension="." mimeType="application/octet-stream" />
   <mimeMap fileExtension=".json" mimeType="application/json" />
  </staticContent>
 </system.webServer>
 </configuration>

更新 2

我终于明白为什么我的 Entitlements.plist 文件不包含关联域的选项。为了看到该选项,您必须右键单击文件 select "Open With..." 并选择 "Property List Editor".

https://docs.microsoft.com/en-us/xamarin/ios/deploy-test/provisioning/entitlements?tabs=vswin

更新 3

我只是 运行 这个验证器工具,一切都是绿色的。它查找 apple-app-site-association 文件。

http://branch.io/resources/aasa-validator/

您的域有效(有效的 DNS)。 您的文件通过 HTTPS 提供。 您的服务器没有 return 大于 400 的错误状态代码。 已找到您文件的 'content-type' header :) 您的 JSON 已通过验证。

更新 4

我刚刚进行了清理、重建和构建。通用链接仍然无效。

更新 5

我升级到 Visual Studio 2017 Enterprise 和 Xamarin.iOS 11.9.1.24。我现在正在使用 11.3 SDK,但仍然无法使用通用链接。我也升级到 Xamarin.Forms 2.5.1.444934。

我遇到了同样的问题,apple-app-site-association 文件验证得很好,我在 AppDelegate.cs 中实现了 ContinueUserActivity 和 OpenUrl 方法,但是从我的网站构建和部署时我的通用链接不起作用Windows 机器使用外部 Mac 构建主机。

所以我认为我应该尝试相同的过程,但这次 运行 我的 Mac 构建主机上的所有内容都在本地 Visual Studio for Mac。 克隆了项目,从我的 phone 中删除了应用程序,重新构建了项目,部署了,瞧,它运行得非常棒。

我终于通过从这一行中删除 space 使其工作。

<string>applinks: portal.mydomain.com</string>

现在是这样写的。

<string>applinks:portal.mydomain.com</string>.

我想通了,因为我在将应用程序提交到应用程序商店时遇到错误。错误是:

your application bundle's signature contains code signing entitlements that are not supported on iOS. Specifically, value applinks: portal.mydomain.com for key com.apple.developer.associated-domains in Payload...