2

There is a whatsapp sharing in my app.

I want to share URL of my app (if app is installed) on whatsapp. If my app is installed in my friends device then it should open my app. But if my app is not installed on the other user(to whom I send the message via whatsapp) device than it should redirect to some website URL in the browser.

I have searched a lot, but could not be successful.

How can i do this ?

Please help me.

Thanks..

AtWork
  • 1,283
  • 1
  • 14
  • 34
Rohan
  • 2,939
  • 5
  • 36
  • 65
  • If you post your app link on whatsapp like itunes.yourapplink.xxxx, it will redirect user to iTunes(if your friend have installed) else app link will open in safari browser. – Gajendra K Chauhan May 15 '14 at 06:04

2 Answers2

0

You need to setup URL scheme for your app see image below

enter image description here

Now when you will share any url on whatsapp, the url should be like below

yourapp://anymessage

The above url will do the work for you..

If you want to test does it work or not.. Try call the app from any other app by using the follow code..

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"yourapp://"]]){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"yourapp://yourmessage"]];
}

I hope it will help you..

Cheers..

Note: If you find anything better please update my answer..

Update If you want the url you share to do all the stuffs for opening app or, web url, you might need some server script like below, I am showing for PHP.

<?php $url="yourapp://".$_GET['message']; ?>
<html>
    <head>
        <title>Your App Title</title>
        <script>
            function redirect(){
                var now = new Date().valueOf();
                setTimeout(function () {
                    if (new Date().valueOf() - now > 100) return;
                       window.location = "YOUR WEB URL";
                    }, 25);
                window.location="<?php echo $url; ?>";
            }
        </script>

    </head>
    <body onload="redirect()">
</html>

And your actual url should look like

http://yourserver.com/script?message=YOURMESSAGE
iphonic
  • 12,615
  • 7
  • 60
  • 107
  • What will happen if I am using the above urlscheme for my app as the whatsapp message "yourapp://anymessage" but my friend is not having my app? My app will not be opened ? Right? – Rohan May 15 '14 at 05:39
  • Ok then in this case i have to open website url. How can i do that? – Rohan May 15 '14 at 06:40
0

How about insert meta tag at redirect webpage's header like this?

<meta http-equiv="refresh" content="0; url=yourapp://anymessage" />

If your app installed it will invoke app or safari will show your webpage with some error alert. For prevent alert message this link could help you.
how to prevent iOS safari alert when trying to open non-installed native app?

Community
  • 1
  • 1
toka
  • 26
  • 4