美文网首页iOS
iOS - Supporting Associated Doma

iOS - Supporting Associated Doma

作者: ienos | 来源:发表于2020-11-20 16:27 被阅读0次

建立域名与应用程序之间的关联

下文中的 associated domain file(域名关联文件) 简写为 asf

// 应用场景

  • Shared web credentials
  • Universal Link
  • Handoff
  • App Clips

// 要求

  • 需要在 website 有相关的 asf
  • App 有相匹配 website 的 Associated Domains Entitlement

// 原理

  • 当用户安装 App 时,当用户安装 App 时,iOS 系统会去 https://<fully qualified domain>/.well-known/apple-app-site-association 尝试下载 asf,并验证域名,并验证域名

一、将 asf 上传到 website 上

  • asf 在 website 上是一个名为 apple-app-site-association 不带扩展名的文件

下面是 apple-app-site-association 一个示例:

{

  "applinks": {

      "details": [

           {

             "appIDs": [ "ABCDE12345.com.example.app", "ABCDE12345.com.example.app2" ],

             "components": [

               {

                  "#": "no_universal_links",

                  "exclude": true,

                  "comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"

               },

               {

                  "/": "/buy/*",

                  "comment": "Matches any URL whose path starts with /buy/"

               },

               {

                  "/": "/help/website/*",

                  "exclude": true,

                  "comment": "Matches any URL whose path starts with /help/website/ and instructs the system not to open it as a universal link"

               },

               {

                  "/": "/help/*",

                  "?": { "articleNumber": "????" },

                  "comment": "Matches any URL whose path starts with /help/ and which has a query item with name 'articleNumber' and a value of exactly 4 characters"

               }

             ]

           }

       ]

   },

   "webcredentials": {

      "apps": [ "ABCDE12345.com.example.app" ]

   },

    "appclips": {

        "apps": ["ABCED12345.com.example.MyApp.Clip"]

    }

}
  • 标记支持的应用程序 <Application Identifier Prefix>.<Bundle Identifier>

<Application Identifier Prefix> 见 App ID 中的 Prefix

image.png
  • detail 仅支持 applink 类型, components 是一个字典数组,匹配 url components

asf 上传到 website 之后,需要的对应的下载链接格式如下: https://<fully qualified domain>/.well-known/apple-app-site-association [要求 https 带有有效证书和不重定向]

二、将相关域名添加到 App 中

  • 打开代码项目,点击 Signing & Capability -> 添加 Associated Domains
  • 做完这步后项目中会自动添加 Associated Domains Entitlement
image.png
  • 在 Associated Domains 中添加对应的域名(会在 Associated Domains Entitlement 填充对应内容),格式如下 <service>:<fully qualified domain>

如果需要匹配一个子域名,可以使用通配符 *

iOS 14 之后,App 将不再直接通过 website 获取 asf,而是通过发送请求到一个 Content Delivery Network(CDN) 做域名关联

如果是局域网通信,可以绕过 CDN 直接连接到域名,在 Associated Domains Entitlement 中添加参数 mode <service>:<fully qualified domain>?mode=<alternate mode>

Alternate Mode

  • developer - - 只有处于开发者模式下的设备才能访问
  • managed - - 指定只有管理 mobile device manangement (MDM) file 才能访问
  • developer+managed - - 同时满足两种模式

相关文章

网友评论

    本文标题:iOS - Supporting Associated Doma

    本文链接:https://www.haomeiwen.com/subject/jaadiktx.html