11

我想使用 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>

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

4

1 回答 1

-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 上安装它会失败),但可能是你唯一能做的事情。

于 2014-05-19T14:13:31.177 回答