将用户重定向到iTunes应用商店还是Google Play商店?

48
8个回答

69

如果你想自己制作而不使用第三方,还有一种JavaScript解决方案:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
<script>
function getMobileOperatingSystem() {
  var userAgent = navigator.userAgent || navigator.vendor || window.opera;

      // Windows Phone must come first because its UA also contains "Android"
    if (/windows phone/i.test(userAgent)) {
        return "Windows Phone";
    }

    if (/android/i.test(userAgent)) {
        return "Android";
    }

    // iOS detection from: https://dev59.com/EGox5IYBdhLWcg3wr2To#9039885
    if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
        return "iOS";
    }

    return "unknown";
}</script>

<script>
function DetectAndServe(){
    let os = getMobileOperatingSystem();
    if (os == "Android") {
        window.location.href = "http://www.Androidexample.com"; 
    } else if (os == "iOS") {
        window.location.href = "http://www.IOSexample.com";
    } else if (os == "Windows Phone") {
        window.location.href = "http://www.WindowsPhoneexample.com";
    } else {
        window.location.href = "http://www.NowherLandexample.com";
    }
}
</script>
</head>
<body onload="DetectAndServe()">
</body>
</html>

24

您是指像这样的内容吗?

Onelink

如何使用 onelink.to

onelink.to 是链接您的应用程序的简单和无忧的方式!

只需添加您的应用程序的 URL,我们 将在每次有人使用您的 onelink.to 地址时确定要使用哪个 URL。

您可以免费使用 onelink.to,无论是私人还是商业用途。我们没有计划改变这一点。

您还可以向您的网站添加备用 URL

希望对您有所帮助。


目标是不使用第三方的。 - Chirry
14
你在哪里看到这句话的?他想要一个简单的解决方案,所以第三方可以是他想要的解决方案。目标不是不使用第三方。 - Strider
如果已经安装了应用程序,您能否使用第三方导航到特定的活动/页面? - Emil
1
备用链接在单行中无法正常工作。 我从计算机重定向到计算机上的 Play Store,而不是备用链接。 - Guy Sela
我需要将Appsflyer链接放在苹果/谷歌链接区域,但在线上会阻止这些链接。有什么办法可以克服这个问题吗? - Uri Abramson
我在使用Google Ads时遇到了一个问题,它会阻止链接到苹果商店的onelink,有没有一种编写中间件来处理这个问题的方法? - pensebien

19

在 PHP 中,你可以使用类似以下的语句:

<?php

$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");

//do something with this information
if( $iPod || $iPhone ){
    //browser reported as an iPhone/iPod touch -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($iPad){
    //browser reported as an iPad -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($Android){
    //browser reported as an Android device -- do something here
    $string = "Location: <<Google Play Link>>";
    header($string);
    die();
}else if($webOS){
    //browser reported as a webOS device -- do something here
    $string = "Location: <<Your Page link>>";
    header($string);
    die();
}else{
    //browser reported as PC -- do something here
    $string = "Location: <<Your Page link>>";
    header($string);
    die();
}


?>

您可以分别使用iTunes或Android的链接:

itms-apps://itunes.apple.com/app/<<App ID>>
market://details?id=<<Package id>>

我不记得消息来源,但至少对我分享到其他应用(如Whatsapp)有效,但不幸的是在Facebook上无法使用。

在Facebook中的问题在于他们使用重定向路径上最终链接的元数据,而该链接指向GooglePlay商店。


6
我们正在寻找一种解决方案,以将用户直接引导到正确的应用商店,并携带额外的元数据,因此当应用在应用商店安装后启动时,它会知道用户来自哪里并启动特定的活动。
因此,如果像我这样的其他人遇到了这篇 Stack Overflow 文章,一个获得 OP 要求以及携带额外元数据(并跟踪所有转换)的提示是查看 Firebase 动态链接:https://firebase.google.com/docs/dynamic-links

3
您可以使用http://toSto.re同时为iTunes和Google Playstore创建短链接。

只需选择一个名称,然后输入不同的应用商店网址,您将获得一个链接,例如toSto.re/facebook,该链接根据用户代理自动指向正确的网址,并支持一些统计数据的Google Analytics集成。


最大的缺点之一是您无法编辑已创建的URL。 - Alexander M.

1

纯JavaScript版本:

<script>
window.addEventListener('DOMContentLoaded', (event) => {
  var userAgent = navigator.userAgent.toLowerCase();
  if (userAgent.indexOf('android') > -1) {
    window.location.href = 'https://play.google.com/store/apps/details?id=de.winterworks.ultimate_puzzle.winterworksGmbH.game';
  } else if (userAgent.indexOf('iphone') > -1 || userAgent.indexOf('ipod') > -1 || userAgent.indexOf('ipad') > -1) {
    window.location.href = 'https://apps.apple.com/us/app/puzzles-for-toddlers-kids/id1463362222';
  }
});

</script>

0

你可以通过后端来创建这个功能。只需创建一个PHP脚本或者你的后端使用的任何语言。在这里我假设是PHP。

只需创建一个PHP脚本,它将确定你正在使用的是iPhone、Android还是Web。查看此链接以获取PHP脚本的示例:移动设备或桌面浏览器检测并重定向到相应的网页

然后将其重定向到相应的URL。例如,你可以使用带有PHP文件的站点URL:https://www.dawawas.com/detect_mobile.php

当用户分享此URL时,其他用户点击上述链接时,PHP脚本将自动确定是iOS、Android还是Web,并通过重定向打开相应的链接。

我已经在我们的iOS应用中实现了这个功能。


0

您可以使用简单的JavaScript代码

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>

<script>
    $(document).ready(function () {
        if (navigator.userAgent.toLowerCase().indexOf("android") > -1) {
            window.location.href = 'market://details?id=<appID>';
        }
        if (navigator.userAgent.toLowerCase().indexOf("iphone") > -1) {
            window.location.href = 'itms-apps://itunes.apple.com/app/<appID>';
        }
    });
</script>

或者如果使用 .net 可以使用

Dim systOS = Request.UserAgent.ToString.ToLower
    
    If (systOS.IndexOf("android").ToString.ToLower > 0) Then
        Response.Redirect("market://details?id=com.manomayelectronics")
        
    ElseIf (systOS.IndexOf("iPod").ToString.ToLower > 0) Then
         Response.Redirect("itms-apps://itunes.apple.com/app/com.manomayelectronics")
 End if

如果使用PHP,可以使用

<?php

$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");


//do something with this information
if( $iPod || $iPhone ){
    //browser reported as an iPhone/iPod touch -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($iPad){
    //browser reported as an iPad -- do something here
    $string = "Location: <<your itunes app link>>";
    header($string);
    die();
}else if($Android){
    //browser reported as an Android device -- do something here
    $string = "Location: <<Google Play Link>>";
    header($string);
    die();
}

敬礼, 多核解决方案。 https://multicoresolutions.in/


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接