7

I have used Custom URL scheme in application. I am successful in redirecting from safari to my app. Like I have make URL scheme "appname". Please check http://prntscr.com/2cjx0p.

I need to use a solution like ios url redirect from mail to app, but I'm not sure on how to set the cookie.

I found that I have to set a cookie for the server "http://myappname.com" in my app first. But how should I do that?


Backstory:

I can use it like by typing "appname://" in safari and I am being redirected to my application.

Now, I have to share this to mail. And requirement is to open application from mail. So, I have also set this link to be clickable in email body. But, because it starts with "appname://", I am not redirected to my application. It means this link must starts with "http://".

Then, I have set "http" instead of "appname" in URL scheme and again share that text. so it will be like "http://". But, by typing this, it doesn't redirect it to my app.

Community
  • 1
  • 1
Krunal
  • 1,318
  • 1
  • 13
  • 31

3 Answers3

6

In the question you link to the code opens a link:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.myApp.com/appInstalled"]];

This opens Safari at a specified page on your server. The only thing that page does is to set a cookie and then redirect back to your app (using the custom URL scheme). This needs to be done by the webpage that is loaded (so using the returned headers & HTML).

The purpose of this is to store the cookie in Safari (that is where it would be required in the future - and it should have an expiry date far in the future). I don't think you can store the cookie in Safari from the app (sandboxing).

You will see a switch to Safari, but it should switch back to your app almost immediately.


You should be able to redirect with javascript in the returned HTML page:

<script type="text/javascript">
<!--
    window.location = "gameswap://?d"
//-->
</script>

or with HTML (in the section):

<meta http-equiv="refresh" content="0; url=gameswap://?d" />
Wain
  • 118,658
  • 15
  • 128
  • 151
  • It opens up but doesn't again redirect to my application. I had implemented it earlier, I faced this issue to again redirect to application. How to do so? – Krunal Dec 20 '13 at 10:34
  • I didn't try the last solution you gave. I have tried up to opening an url that you said. From where to call it? – Krunal Dec 20 '13 at 10:48
  • Sorry, I don't understand that comment. The page returned from the server should have a header with the cookie and a bit of HTML just with a redirect in it. – Wain Dec 20 '13 at 11:13
4

I solved this...

What I have done this by having live url, contained with Test.html page. In that, below script is written..

<script type="text/javascript">
window.location = 'appName://';
</script>

Now, while sharing url, it is like 'http://demo.com/test.php/?d='. And from mail, I opened that link, and it is already redirected to my application's specific page.

I found the biggest help from HERE.

Community
  • 1
  • 1
Krunal
  • 1,318
  • 1
  • 13
  • 31
1

Use this format If you don't want to use http.

Set this in your URL scheme

www.my.app

Link Format to open app

www.<characters>.<characters>://<characters>

for eg.

www.my.app://open
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65