Question

I am new to iOS and objective C. I have to create a simple app where user will press a button and as a result, app will open safari. Then user have to come back to my app again. I have opened safari but I don't know how to bring user back to my app. I have used this simple code:

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

Any suggestion that how I can do that?

Was it helpful?

Solution

When you open a URL using

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

Your OS takes care of loading a new application. Instead if you wanna load a web URL use apple's UIWebView class.

OTHER TIPS

I think you can't do this, only on your own urls following this:

First of all you want a custom scheme. https://coderwall.com/p/mtjaeq

[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:@"http://www.yourserver.com/file.php"]];

Now because the url is point at your own server you can redirect using the scheme that you create eg. myapp://.

In your server, in file.php if you set this:

<script type="text/javascript">location.href="myapp://"</script>

Then will came back in your app.

If you can't control the page you are sending them to, no you can't do this.

If you want to remind them to come back, you could schedule a UILocalNotification to appear a few seconds after opening the URL - if they touch this they will be brought back into your app. This will pop up on screen as an alert or a banner depending on the current user preferences.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top