【问题标题】:How to detect if opening a "twitter://" URL will succeed?如何检测打开“twitter://”URL 是否会成功?
【发布时间】:2012-07-19 17:05:32
【问题描述】:

我想使用 Twitter 应用程序从我的网络应用程序发送推文,而不是在安装 twitter 客户端时使用 twitter 按钮。

如果我在 iPhone 或 Mac 上安装了 Twitter 应用程序,则在将 Web 应用程序重定向到“twitter://”网址时会打开此应用程序。 (见http://handleopenurl.com/scheme/twitter

但如果我只想在未安装 Twitter 应用程序的地方显示 Twitter 按钮,我该如何检查呢?假设我有这个代码。 twitter_app_installed() 应该如何?有没有办法检查window.location="twitter://..."; 是否不起作用?

<div class="twitter-button"><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://google.com" data-text="Hello World">Tweet</a></div>
<div class="twitter-app-button"><a href="twitter://post?message=Hello%20World%20http://google.com">Tweet</a></div>

<script>
function twitter_app_installed() { /* check if window.location="twitter://"; works */}
$(document).ready(function() {
  if (twitter_app_installed()) $('.twitter-app-button').show();
  else $('.twitter-button').show();
});
</script>

Plus:是否有正确的方法将 URL 添加到 twitter:// 方案?

【问题讨论】:

标签: javascript twitter url-scheme


【解决方案1】:

似乎无法进行这种类型的检查。

我认为(在 iPhone 上)你能做的最好的事情是:

a) 在首次用户访问时始终显示“下载应用程序”

b) 在按钮单击事件上执行类似的操作:

setTimeout(function () { 
    window.location = "your store url here";    
}, 25);
document.cookie="is_app_installed=true"
window.location = "appname://";

只有在未安装应用时才会触发设置的超时

c) 从第二个用户访问,您可以使用cookie来检查应用程序是否已安装。

这个方法有很多不足(如果用户卸载应用程序或不在 iTunes 上安装它会失败),但可能是你唯一能做的。

【讨论】:

    猜你喜欢
    • 2011-05-11
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    • 2011-09-04
    • 2013-08-26
    • 2011-09-09
    相关资源
    最近更新 更多