You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Maui iOS深度链接优化:未安装应用时跳转App Store

解决.NET Maui iOS深度链接未安装时跳转App Store的配置修改

要实现未安装App时点击深度链接直接跳转App Store,需要修改以下几部分配置:

1. Apple开发者后台与项目Info.plist配置

  • 登录Apple开发者后台,找到你的App ID,启用Associated Domains功能,添加applinks:<你的域名>(替换为实际域名)。
  • 在Maui项目的Platforms/iOS/Info.plist中添加关联域名与网络权限配置:
    <key>com.apple.developer.associated-domains</key>
    <array>
        <string>applinks:你的域名</string>
    </array>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>你的域名</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
                <key>NSAllowsArbitraryLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    

2. 更新网站的apple-app-site-association文件

  • 在你的域名根目录下创建.well-known文件夹,放入apple-app-site-association文件(无后缀),内容示例:
    {
        "applinks": {
            "details": [
                {
                    "appID": "你的TeamID.你的BundleID",
                    "paths": ["*"]
                }
            ]
        }
    }
    
  • 确保该文件可被公开访问,且响应的Content-Type为application/json,无跳转重定向。

3. 网站端添加跳转逻辑

在深度链接对应的网页中加入JS检测逻辑,当无法唤起App时自动跳转App Store:

window.addEventListener('DOMContentLoaded', () => {
    const appStoreUrl = 'https://apps.apple.com/地区/app/应用名称/id你的AppID';
    const deepLink = '你的深度链接协议://目标路径';
    
    const timeout = setTimeout(() => {
        window.location.href = appStoreUrl;
    }, 1000);

    window.location.href = deepLink;

    // 若App唤起成功,清除跳转定时器
    window.addEventListener('blur', () => clearTimeout(timeout));
});

4. 确认Maui项目的深度链接回调处理

在Platforms/iOS/AppDelegate.cs中确保正确处理深度链接回调,保证App安装后能正常响应:

public override bool ContinueUserActivity(UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
    if (userActivity.ActivityType == NSUserActivityType.BrowsingWeb && userActivity.WebPageUrl != null)
    {
        // 处理深度链接的业务逻辑
        return true;
    }
    return base.ContinueUserActivity(application, userActivity, completionHandler);
}

内容的提问来源于stack exchange,提问作者Csaba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 09:54:56