4

In one of my iOS App, I have to just launch the Safari App and not open some specific Url in Safari which can be achieved by this:

NSURL *url = [NSURL URLWithString:@"http://www.stackoverflow.com"];

if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}

But I only need to launch safari App with last tab open (in the same state that I leave before entering that iOS App).

Any suggestion and help will be welcome. Thanks!

Irfan
  • 4,301
  • 6
  • 29
  • 46

2 Answers2

1

Actually we can open a specific app from safari. You have to create a custom url scheme for the application and open that link from safari like any other link is opened from safari.

Create a custom url scheme like

myApp://

Then open it from safari e.g on onClick of button.

0

Objective C

NSURL *url = [NSURL URLWithString:@"http://about:blank"];
if (![[UIApplication sharedApplication] openURL:url]) {
    NSLog(@"%@%@",@"Failed to open url:",[url description]);
}  

Swift 3.0

UIApplication.shared().openURL(URL(string: "http://about:blank")!)

Hope It will help you.

Add Comment if you require any other information.

Ketan P
  • 4,259
  • 3
  • 30
  • 36
  • You just mentioned this didn't work in the comment. And now when it worked for you, you deleted the comment and wrote the same answer. – Nitish Jul 01 '16 at 06:49
  • Ok. That's fair. Removing my down vote and upvoting it. – Nitish Jul 01 '16 at 06:53
  • @Irfan you can tick as answer if it helps you. – Ketan P Jul 01 '16 at 06:59
  • 1
    Only need to launch safari App and restore the last tab open(in the same state that I leave before entering that iOS App) and not wants to open the blank page. – Irfan Jul 01 '16 at 07:02
  • @Irfan ok Let me check if I can solve this. I drafted and post answer mean while you edit the question. Thats I don't read. anyways let me check if I can help you !!! – Ketan P Jul 01 '16 at 07:20