为 iOS 配置通用链接
了解如何为使用 Flutter 构建的 iOS 应用配置通用链接。
深度链接允许应用用户通过 URI 启动应用。该 URI 包含 scheme、host 和 path,可将应用打开到特定屏幕。
通用链接 是一种仅适用于 iOS 设备的深度链接类型,只使用 http 或 https 协议。
要配置通用链接,你需要拥有自己的网站域名。作为临时方案,可考虑使用 Firebase Hosting 或 GitHub Pages。
配置好深度链接后,你可以验证它们。了解更多,请参阅 验证深度链接。
创建或修改 Flutter 应用
#编写能处理传入 URL 的 Flutter 应用。
本示例使用 go_router package 处理路由。
Flutter 团队维护 go_router package。它提供简单的 API 来处理复杂的路由场景。
-
要创建新应用,输入
flutter create <app-name>。flutter create deeplink_cookbook -
要将
go_routerpackage 添加为依赖,运行flutter pub add:flutter pub add go_router -
要处理路由,在
main.dart文件中创建GoRouter对象:main.dartdartimport 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; void main() => runApp(MaterialApp.router(routerConfig: router)); /// This handles '/' and '/details'. final router = GoRouter( routes: [ GoRoute( path: '/', builder: (_, _) => Scaffold( appBar: AppBar(title: const Text('Home Screen')), ), routes: [ GoRoute( path: 'details', builder: (_, _) => Scaffold( appBar: AppBar(title: const Text('Details Screen')), ), ), ], ), ], );
调整 iOS 构建设置
#启动 Xcode。
-
打开 Flutter 项目
ios文件夹内的ios/Runner.xcworkspace文件。
添加关联域
#如有必要,启动 Xcode。
点击顶层的 Runner。
-
在编辑器中,点击 Runner target。
-
点击 Signing & Capabilities。
-
要添加新域,在 Signing & Capabilities 下点击 + Capability。
-
点击 Associated Domains。

-
在 Associated Domains 部分,点击 +。
-
输入
applinks:<web domain>。将<web domain>替换为你自己的域名。
-
在你偏好的编辑器中打开
ios/Runner/Runner.entitlementsXML 文件。 -
在
<dict>标签内添加关联域。xml<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.developer.associated-domains</key> <array> <string>applinks:example.com</string> </array> </dict> </plist> -
保存
ios/Runner/Runner.entitlements文件。
要检查你创建的关联域是否可用,请执行以下步骤:
如有必要,启动 Xcode。
点击顶层的 Runner。
-
在编辑器中,点击 Runner target。
-
点击 Signing & Capabilities。域应出现在 Associated Domains 部分。

你已完成应用的深度链接配置。
将应用与网站域名关联
#
你需要在网站域名上托管 apple-app-site-association 文件。该文件告诉移动浏览器应打开哪个 iOS 应用,而不是浏览器。要创建该文件,请找到上一节创建的 Flutter 应用的 appID。
定位 appID 的组成部分
#
Apple 将 appID 格式化为 <team id>.<bundle id>。
在 Xcode 项目中定位 bundle ID。
-
在 开发者账户 中定位 team ID。
例如: 给定 team ID 为 S8QB4VV633,
bundle ID 为 com.example.deeplinkCookbook,你应输入 appID 条目
S8QB4VV633.com.example.deeplinkCookbook。
创建并托管 apple-app-site-association JSON 文件
#
该文件使用 JSON 格式。保存时不要包含 .json 文件扩展名。根据 Apple 文档,该文件应类似以下内容:
{
"applinks": {
"apps": [],
"details": [
{
"appIDs": [
"S8QB4VV633.com.example.deeplinkCookbook"
],
"paths": [
"*"
],
"components": [
{
"/": "/*"
}
]
}
]
},
"webcredentials": {
"apps": [
"S8QB4VV633.com.example.deeplinkCookbook"
]
}
}
-
将
appIDs数组中的一个值设为<team id>.<bundle id>。 -
将
paths数组设为["*"]。paths数组指定允许的通用链接。使用星号*会将每个路径重定向到 Flutter 应用。如有需要,将paths数组值改为更适合你应用的设置。 -
在类似以下结构的 URL 托管该文件。
<webdomain>/.well-known/apple-app-site-association 验证浏览器能否访问该文件。
测试通用链接
#使用实体 iOS 设备或模拟器测试通用链接。
-
测试前,在 iOS 设备或模拟器上安装 Flutter 应用,在目标设备上使用
flutter run。
完成后,Flutter 应用会显示在 iOS 设备或模拟器的主屏幕上。
-
如果使用模拟器测试,使用 Xcode CLI:
xcrun simctl openurl booted https://<web domain>/details -
如果使用实体 iOS 设备测试:
启动 备忘录 应用。
在 备忘录 应用中输入 URL。
点击生成的链接。
如果成功,Flutter 应用会启动并显示其详情屏幕。

查找源代码
#你可以在 GitHub 仓库中找到 deeplink_cookbook 示例 食谱的源代码。
除非另有说明,本文档之所提及适用于 Flutter 3.44.0 版本。本页面最后更新时间:2026-06-04。查看文档源码 或者 为本页面内容提出建议。