Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom URL scheme starting with http not working

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.

like image 696
Krunal Avatar asked Dec 20 '13 09:12

Krunal


2 Answers

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" />
like image 94
Wain Avatar answered Sep 23 '22 13:09

Wain


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.

like image 35
Krunal Avatar answered Sep 20 '22 13:09

Krunal