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

如何根据接收者设备平台分享对应App Store/Play Store链接?

根据接收者设备平台分享对应应用商店链接的解决方案

你的问题核心在于当前代码只判断了分享者的设备平台,无法适配接收者的设备。要解决这个问题,有几种实用的方案:

方案1:自建智能跳转页面(最易实现)

搭建一个简单的静态网页,当接收者打开链接时,页面通过JS识别设备类型,自动跳转到对应应用商店。分享时只需要分享这个跳转页的链接即可。

跳转页面核心JS代码:

window.addEventListener('load', () => {
  const userAgent = navigator.userAgent.toLowerCase();
  const iosStoreLink = "https://apps.apple.com/~~~"; // 替换为你的App Store链接
  const androidStoreLink = "https://play.google.com/~~~"; // 替换为你的Play Store链接
  const fallbackLink = "https://your-app-official-site.com"; // 桌面端或未知设备的备用链接

  if (userAgent.includes('iphone') || userAgent.includes('ipad')) {
    window.location.href = iosStoreLink;
  } else if (userAgent.includes('android')) {
    window.location.href = androidStoreLink;
  } else {
    window.location.href = fallbackLink;
  }
});

Flutter端分享代码修改:

Link(
  mobileWebUrl: Uri.parse("https://your-redirect-page.com"), // 替换为你的跳转页链接
),

方案2:使用动态链接插件(更专业的原生适配)

借助Flutter的动态链接插件(比如firebase_dynamic_links),通过第三方服务自动处理设备识别和跳转:

  1. 在对应平台控制台配置好应用商店的链接参数
  2. 生成动态链接并分享,接收者打开时会自动匹配设备跳转

代码示例:

import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';

// 生成动态链接
Future<String> generateDynamicLink() async {
  final params = DynamicLinkParameters(
    uriPrefix: 'https://yourapp.page.link', // 替换为你的动态链接前缀
    link: Uri.parse('https://your-app-site.com'), // 原始链接
    iosParameters: const IOSParameters(
      appStoreId: 'your-appstore-id', // 你的App Store ID
      bundleId: 'com.your.ios.bundle', // iOS包名
    ),
    androidParameters: const AndroidParameters(
      packageName: 'com.your.android.package', // Android包名
      minimumVersion: 1,
    ),
  );

  final shortLink = await params.buildShortLink();
  return shortLink.shortUrl.toString();
}

// 分享时使用生成的动态链接
Link(
  mobileWebUrl: Uri.parse(await generateDynamicLink()),
),

方案3:备选方案 - 提供双链接

如果不想依赖外部服务或页面,可以在分享内容里同时给出两个应用商店的链接,让接收者自行选择。这种方式体验稍差,但实现成本最低。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 01:50:20