确定应用程序是否存在并在 iOS 上启动该应用程序

发布于 2024-11-02 14:09:33 字数 68 浏览 1 评论 0原文

有没有办法检查 iOS 是否已安装并启动了另一个应用程序?如果我没记错的话,这在早期版本中是不可能的,但是这已经改变了吗?

Is there a way to check iOS to see if another app has been installed and then launched? If memory serves me this was not possible in early versions but has this been changed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

尽揽少女心 2024-11-09 14:09:33

可行,但很棘手。

启动已安装的应用程序(例如 FB 或 Twitter 应用程序)是使用自定义 URL 方案完成的。这些可以在其他应用程序和网站上使用。

这里有一篇关于如何执行此操作的文章使用您自己的应用程序

不过,查看 URL 是否存在可能会很棘手。 Boxcar 是检测已安装应用程序的一个很好的示例。这里的问题是 Boxcar 对自定义 URL 有深入的了解。我相当 (99%) 确定存在 canOpenURL:,因此提前了解您想要定位的应用程序的自定义方案可以使实现变得简单。

这是部分列表 您可以检查一些更流行的 URL。

有一种方法可以找到自定义应用程序 URL: https://www.amerhukic.com/finding-the-custom-url-scheme-of-an-ios-app

但是如果你想扫描应用程序并推断出它们的 URL,它就不能在非 JB 设备上完成。

这是一篇博客文章,讨论 Bump 的人员如何处理该问题。

Doable, but tricky.

Launching installed apps, like the FB or Twitter apps, is done using the Custom URL Scheme. These can be used both in other apps as well as on web sites.

Here's an article about how to do this with your own app.

Seeing if the URL is there, though, can be tricky. A good example of an app that detects installed apps is Boxcar. The thing here is that Boxcar has advanced knowledge of the custom URL's. I'm fairly (99%) certain that there is a canOpenURL:, so knowing the custom scheme of the app you want to target ahead of time makes this simple to implement.

Here's a partial list of some of the more popular URL's you can check against.

There is a way to find out the custom app URL : https://www.amerhukic.com/finding-the-custom-url-scheme-of-an-ios-app

But if you want to scan for apps and deduce their URL's, it can't be done on a non-JB device.

Here's a blog post talking about how the folks at Bump handled the problem.

抠脚大汉 2024-11-09 14:09:33

有一个如下所示的脚本。

<script type="text/javascript">
function startMyApp()
{
  document.location = 'yourAppScheme://';
  setTimeout( function()
  {
      if( confirm( 'You do not seem to have Your App installed, do you want to go download it now?'))
      {
        document.location = 'http://itunes.apple.com/us/app/yourAppId';
      }
  }, 300);
 }
</script>

从网络调用此脚本 (尝试启动 MyApp),您可以确定您的应用程序是否具有方案“ yourAppScheme”是否安装在设备上。

如果应用程序安装在设备上并且在其中注册了“yourAppScheme”,则该应用程序将启动。
如果未安装该应用程序,您可以建议用户从 iTunes 安装该应用程序。

There is a script like the following.

<script type="text/javascript">
function startMyApp()
{
  document.location = 'yourAppScheme://';
  setTimeout( function()
  {
      if( confirm( 'You do not seem to have Your App installed, do you want to go download it now?'))
      {
        document.location = 'http://itunes.apple.com/us/app/yourAppId';
      }
  }, 300);
 }
</script>

Calling this script from the web (<a href="#" onclick="startMyApp()">Try to start MyApp</a>), you can determine if your app with scheme "yourAppScheme" is installed on the device or not.

The App will launch if it is installed on the device and "yourAppScheme" is registered in it.
If the app is not installed you can suggest the user to install this app from iTunes.

要走就滚别墨迹 2024-11-09 14:09:33

要检查是否安装了应用程序(例如 Clear):

BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"clearapp://"]];

要打开该应用程序:

BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"clearapp://"]];

To check if an app is installed (e.g. Clear):

BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"clearapp://"]];

To open that app:

BOOL success = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"clearapp://"]];
柠北森屋 2024-11-09 14:09:33

如果未安装应用程序,则隐藏错误消息

Branch 中,我们使用以下代码的形式--注意 iframe 适用于更多浏览器。只需替换您应用程序的 URI 和您的 App Store 链接即可。

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // Deep link to your app goes here
                document.getElementById("l").src = "my_app://";

                setTimeout(function() {
                    // Link to the App Store should go here -- only fires if deep link fails                
                    window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
                }, 500);
            };
        </script>
        <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
    </body>
</html>

还有第二种可能性,即首先依赖 cookie,然后将 javascript 重定向仅作为后备。逻辑如下:

当没有该应用程序的用户首次点击您的应用程序的链接时,他或她会被直接重定向到应用程序商店。这是通过指向您的应用程序的链接来完成的,该应用程序实际上是带有重定向的服务器上动态生成的页面。您创建 cookie 并在后端记录 IP 地址、操作系统、操作系统版本等的“数字指纹”。

当用户安装应用程序并打开它时,您会收集另一个“数字指纹”并将其发送到后端。现在您的后端知道该链接已安装。在任何后续访问与您的应用程序关联的链接时,您的服务器都会根据随请求发送的 cookie,确保动态生成的重定向页面指向该应用程序,而不是 App Store。

这避免了丑陋的重定向,但涉及大量的工作。

Hides the error message if the app is not installed

At Branch we use a form of the code below--note that the iframe works on more browsers. Simply substitute in your app's URI and your App Store link.

<!DOCTYPE html>
<html>
    <body>
        <script type="text/javascript">
            window.onload = function() {
                // Deep link to your app goes here
                document.getElementById("l").src = "my_app://";

                setTimeout(function() {
                    // Link to the App Store should go here -- only fires if deep link fails                
                    window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
                }, 500);
            };
        </script>
        <iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
    </body>
</html>

There's a second possibility that relies on cookies first and the javascript redirect only as a fallback. Here's the logic:

When a user without the app first taps on a link to your app, he or she is redirected straight to the App Store. This is accomplished by a link to your app actually being a dynamically-generated page on your servers with the redirect. You create a cookie and log a "digital fingerprint" of IP address, OS, OS version, etc. on your backend.

When the user installs the app and opens it, you collect and send another "digital fingerprint" to your backend. Now your backend knows the link is installed On any subsequent visits to links associated with your app, your servers make sure that the dynamically-generated redirect page leads to the app, not the App Store, based on the cookie sent up with the request.

This avoids the ugly redirect but involves a ton more work.

茶底世界 2024-11-09 14:09:33

据我了解,由于隐私问题,您无法看到设备上是否安装了应用程序。解决这个问题的方法是尝试启动应用程序,如果它没有启动,则让用户点击回退网址。为了防止发生移动 Safari 错误,我发现将其放置在 iframe 中有助于解决该问题。

这是我使用的一段代码。

<form name="mobileForm" action="mobile_landing.php" method="post">
        <input type="hidden" name="url" value="<?=$web_client_url?>">
        <input type="hidden" name="mobile_app" value="<?=$mobile_app?>">
        <input type="hidden" name="device_os" value="<?=$device_os?>">
    </form>
<script type="text/javascript">
        var device_os = '<? echo $device_os; ?>'; 


        if (device_os == 'ios'){

        var now = new Date().valueOf(); 
        setTimeout(function () { 
            if (new Date().valueOf() - now > 100) 
                return;

        document.forms[0].submit(); }, 5); 


        var redirect = function (location) {
            var iframe = document.createElement('iframe');
            iframe.setAttribute('src', location);
            iframe.setAttribute('width', '1px');
            iframe.setAttribute('height', '1px');
            iframe.setAttribute('position', 'absolute');
            iframe.setAttribute('top', '0');
            iframe.setAttribute('left', '0');
            document.documentElement.appendChild(iframe);
            iframe.parentNode.removeChild(iframe);
            iframe = null;
        };

        setTimeout(function(){
            window.close()
            }, 150 );

        redirect("AppScheme");

To my understanding, because of privacy issues, you can't see if an app is installed on the device. The way around this is to try and launch the app and if it doesn't launch to have the user hit the fall back url. To prevent the mobile safari error from occurring I found that placing it in an iframe helps resolve the issue.

Here's a snippet of code that I used.

<form name="mobileForm" action="mobile_landing.php" method="post">
        <input type="hidden" name="url" value="<?=$web_client_url?>">
        <input type="hidden" name="mobile_app" value="<?=$mobile_app?>">
        <input type="hidden" name="device_os" value="<?=$device_os?>">
    </form>
<script type="text/javascript">
        var device_os = '<? echo $device_os; ?>'; 


        if (device_os == 'ios'){

        var now = new Date().valueOf(); 
        setTimeout(function () { 
            if (new Date().valueOf() - now > 100) 
                return;

        document.forms[0].submit(); }, 5); 


        var redirect = function (location) {
            var iframe = document.createElement('iframe');
            iframe.setAttribute('src', location);
            iframe.setAttribute('width', '1px');
            iframe.setAttribute('height', '1px');
            iframe.setAttribute('position', 'absolute');
            iframe.setAttribute('top', '0');
            iframe.setAttribute('left', '0');
            document.documentElement.appendChild(iframe);
            iframe.parentNode.removeChild(iframe);
            iframe = null;
        };

        setTimeout(function(){
            window.close()
            }, 150 );

        redirect("AppScheme");
纵情客 2024-11-09 14:09:33

我最近为此苦苦挣扎,这是我想出的解决方案。请注意,仍然没有可靠的方法来检测应用程序是否启动。

我从我的服务器提供一个页面,该页面在检测到用户代理后重定向到 iPhone 特定的变体。该页面的链接只能通过电子邮件/短信或 Facebook 共享。

该页面呈现所引用文档的最小版本,但随后会在加载后自动尝试使用隐藏的

如果注册了 URL 方案,应用程序将打开,用户将能够执行他们需要的所有操作。无论哪种方式,页面都会在底部显示类似这样的消息:“应用程序启动了吗?如果没有,您可能还没有安装它......”,并带有指向商店的链接。

I struggled with this recently, and here is the solution I came up with. Notice that there is still no surefire way to detect whether the app launched or not.

I serve a page from my server which redirects to an iPhone-specific variant upon detecting the User-Agent. Links to that page can only be shared via email / SMS or Facebook.

The page renders a minimal version of the referenced document, but then automatically tries to open the app as soon as it loads, using a hidden <iframe> (AJAX always fails in this situation -- you can't use jQuery or XMLHttpRequest for this).

If the URL scheme is registered, the app will open and the user will be able to do everything they need. Either way, the page displays a message like this at the bottom: "Did the app launch? If not, you probably haven't installed it yet .... " with a link to the store.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文