11

I want to use the Twitter App to send a tweet from my web app, instead of using the twitter button when a twitter client is installed.

If I am on an iPhone or Mac with the Twitter App installed, this app opens when redirecting the web app to a "twitter://" url. (see http://handleopenurl.com/scheme/twitter)

But if I want to show the Twitter Button only where the Twitter App isn't installed, how do I check for this? Suppose I have this code. How should twitter_app_installed() be? Is there a way to check if window.location="twitter://..."; won't work?

<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: is there a correct way of adding a URL to the twitter:// scheme?

Martin Schaer
  • 3,986
  • 1
  • 23
  • 28

1 Answers1

-1

It seems it not possible do this type of check.

I think (on iphone) the best think you can do is:

a) show always "Download App" on the first user access

b) execute something like this on the button click event:

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

the set timeout will be triggered only if the app is not instaled

c) from the second user access, you can use the cookie to check if the app is installed.

this approch have a lot of lacks (it will fail if the user uninstall the app or not install it on itunes), but probaably is the only thing you can do.

Jurgo Boemo
  • 1,690
  • 1
  • 15
  • 21