如果安装,则重定向到应用程序,否则重定向到App Store

Con*_*oob 60 redirect app-store ios

我知道可以通过注册自定义方案(例如so://)直接链接到iOS中的应用程序,也可以通过iTunes链接到appstore中的应用程序.

在许多情况下,理想的流程是提供一个链接,如果安装了应用程序,重定向到应用程序,如果没有,则提供给商店.这是可能的,如果是的话,怎么样?

为了清楚起见,添加的方案是我在iphone上打开一个电子邮件链接(http),邀请我加入应用程序中的一个组.如果用户在该设备上安装了应用程序,则应该打开,否则http链接应该重定向到iTunes.

Ban*_*eil 54

我认为更简单的答案是使用以下javascript在您的服务器上设置页面:

(function() {
  var app = {
    launchApp: function() {
      window.location.replace("myapp://");
      this.timer = setTimeout(this.openWebApp, 1000);
    },

    openWebApp: function() {
      window.location.replace("http://itunesstorelink/");
    }
  };

  app.launchApp();
})();
Run Code Online (Sandbox Code Playgroud)

这基本上会尝试重定向到您的应用并设置超时,以便在应用商店失败时重定向到应用商店.

您甚至可以使代码更加智能,并检查用户代理以查看它们是否是ios用户,Android用户或webuser,然后适当地重定向它们.

  • 如果没有使用此方法安装应用程序,iOS会引发一个相当不友好的"Safari无法打开页面因为地址无效"消息. (9认同)
  • 应该考虑接受的答案. (7认同)
  • @RealWorld这听起来像是ios 11的新增功能.现在,对于这个主题,我建议实现通用链接.可能值得为这个问题写一个新的答案,概述它是如何工作的. (3认同)
  • 它曾经工作过,但我相信它已在ios 12中停止工作。或其他原因出故障,导致其突然停止工作。 (3认同)
  • 是的,这曾经在 IOS 12 之前工作,现在不幸的是它会打开一个应用程序并链接两者 (2认同)

Lef*_*ris 26

没有办法检查这个.但是,有一个很好的解决方法.

这个想法基本上是这样的:

  1. 第一次打开应用程序时,您可以在应用程序中打开移动safari到服务器上的预定义URL
  2. 在该URL上,您可以设置一个cookie,例如appInstalled给用户的移动版Safari
  3. 然后使用您的注册方案将用户踢回您的应用程序(与FB对SSO相同)
  4. 您的所有电子邮件链接都指向您的网站,但在网站上您检查浏览器是否为移动版Safari以及是否存在appInstalled cookie
  5. 如果浏览器不是移动版Safari或找不到cookie,您将重定向到AppStore,或保留在您的网页中.
  6. 如果#4的条件为真,则使用注册的方案将用户重定向到您的应用程序
  7. 如果用户已删除该应用程序,因此自定义URL方案失败,则您具有到appstore的故障安全重定向

最后两个步骤在此SO帖子中进行了解释

  • 这个答案仍然准确吗?有人知道吗 我看到像BOA和Medium这样的应用程序甚至都没有打开Safari就能打开! (2认同)

q0r*_*ban 14

如果你有一个网页,你用含有网页的电子邮件链接到iframesrc一套为您的应用程序自定义方案,,iOS将自动重定向到在App该位置.如果未安装该应用程序,则不会发生任何事情.这允许您深入链接到应用程序(如果已安装),或者如果未安装则重定向到App Store.

例如,如果您安装了Twitter应用程序,并导航到包含以下标记的网页,您将立即转到该应用程序.如果您没有安装Twitter应用程序,您会看到文本"未安装Twitter应用程序".

<!DOCTYPE html>
<html>
    <head>
    <title>iOS Automatic Deep Linking</title>
    </head>
    <body>
        <iframe src="twitter://" width="0" height="0"></iframe>
        <p>The Twitter App is not installed</p>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是一个更全面的示例,如果未安装App,则重定向到App Store:

<!DOCTYPE html>
<html>
    <head>
    <title>iOS Automatic Deep Linking</title>
    <script src='//code.jquery.com/jquery-1.11.2.min.js'></script>
    <script src='//mobileesp.googlecode.com/svn/JavaScript/mdetect.js'></script>
    <script>
      (function ($, MobileEsp) {
        // On document ready, redirect to the App on the App store.
        $(function () {
          if (typeof MobileEsp.DetectIos !== 'undefined' && MobileEsp.DetectIos()) {
            // Add an iframe to twitter://, and then an iframe for the app store
            // link. If the first fails to redirect to the Twitter app, the
            // second will redirect to the app on the App Store. We use jQuery
            // to add this after the document is fully loaded, so if the user
            // comes back to the browser, they see the content they expect.
            $('body').append('<iframe class="twitter-detect" src="twitter://" />')
              .append('<iframe class="twitter-detect" src="itms-apps://itunes.com/apps/twitter" />');
          }
        });
      })(jQuery, MobileEsp);
    </script>
    <style type="text/css">
      .twitter-detect {
        display: none;
      }
    </style>
    </head>
    <body>
    <p>Website content.</p>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)


Wil*_*iuk 8

"智能应用程序横幅" - 不确定他们何时出现,但在找到这篇文章寻找相同内容后,智能应用程序横幅,这是后续行动.

智能应用横幅是您希望通过网络体验为您的应用提供的每个页面标题中的单行html元标记:

<meta name="apple-itunes-app" content="app-id=myAppStoreID, affiliate-data=myAffiliateData, app-argument=myURL">
Run Code Online (Sandbox Code Playgroud)

它显示页面顶部的图标和"使用应用程序打开此页面"或路由到App Store.

在此输入图像描述

iPhone上此页面的元数据如下所示(当然是匿名的):

<meta name="apple-itunes-app" content="app-id=605841731, app-argument=lync://confjoin?url=https://meet.rtc.yourcorporatedomain.com/firstName.lastName/conferenceID">
Run Code Online (Sandbox Code Playgroud)

Apple 开发人员文档 - 使用智能应用程序横幅推广应用程序


roo*_*117 7

是的,非常容易.这需要您要打开的应用程序在plist中声明一个url方案:

//if you can open your app
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yourapp://"]])
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourapp://"]];
}
else
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ituneappstorelink"]];
}
Run Code Online (Sandbox Code Playgroud)


aft*_*han 5

只需几个简单的步骤即可实现此操作

步骤1

转到 -> 项目(选择目标) -> 信息 -> URL 类型

在此输入图像描述

像这样在 Xcode 中创建 URL 方案

在此输入图像描述 这里的URLScheme是myApp(最好所有字符都是小写)。

第2步

如果您计划从 URL 接收参数/查询字符串,请设置委托

这是代码:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {

     NSLog(@"APP : simple action %@",url.scheme);

    if ([url.scheme hasPrefix:@"myapp"]) {

        NSLog(@"APP inside simple %@",url.absoluteString);


        NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:url
                                                    resolvingAgainstBaseURL:NO];
        NSArray *queryItems = urlComponents.queryItems;
        NSString * abc = [self valueForKey:@"abc"
                           fromQueryItems:queryItems];
        NSString * xyz = [self valueForKey:@"xyz"
                           fromQueryItems:queryItems];


        NSLog(@"Sid up = %@", abc);

        NSLog(@"PID up = %@", xyz);

      // you can do anything you want to do here



        return YES;
    }
return NO;
}
Run Code Online (Sandbox Code Playgroud)

Xcode 端工作结束。

步骤3

在这里引用 @BananaNeil 代码,因为我不是前端人员

(function() {
  var app = {
    launchApp: function() {
      window.location.replace("myApp://share?abc=12&xyz=123");
      this.timer = setTimeout(this.openWebApp, 1000);
    },

    openWebApp: function() {
      window.location.replace("http://itunesstorelink/");
    }
  };

  app.launchApp();
})();
Run Code Online (Sandbox Code Playgroud)

希望对大家有所帮助