android - 将用户重定向到 iTunes 应用商店或 Google Play 商店?

标签 android ios iphone facebook

我正在寻找一种简单的解决方案来发布我的应用的一个链接,例如在 Facebook 上,如果用户使用移动设备访问它,它应该会自动重定向到正确的应用商店。否则用户应该被重定向到我的网站。

iOS 应用程序: http://itunes.apple.com/de/app/dawawas/id588285122

安卓应用: https://play.google.com/store/apps/details?id=de.conceptspace.dawawas.greenturtle&hl=en

网站: https://www.dawawas.com/

最佳答案

如果您想自己推出而不使用第三方,还有一个 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: http://stackoverflow.com/a/9039885/177710
    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>

关于android - 将用户重定向到 iTunes 应用商店或 Google Play 商店?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35430336/

相关文章:

java - TextView setText 不起作用

android - 模拟器 : emulator window was out of view and was recentered

ios - 使用 uiactivityviewcontroller 共享图像和视频

ios - 在相机捕获和图像编辑时使用 GPUImage GaussianSelective Blur Filter

iphone - 定义屏幕宽度常量

ios - 当点击 UIcollectionviewcell 放大单元格照片并打开新的 View Controller 时

java - InputListener 不设置新屏幕

ios - 放入操作队列时网络操作不再完成

ios - iOS 7中不显示社交 View 的默认警报

android - 单击最后一个 fragment 时出现错误