5

I want to open the Mobile Safari app "WITHOUT" changing its currently displayed page.

I can easily switch to Safari using ..

NSString *ourPath = @"http://www.google.co.uk";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
    [ourApplication openURL:ourURL];
}

But what I want to do is just switch to safari and not navigate away from the page it is currently on. Like when I switch using the task switcher, it just pops Safari and leaves it on the page it was.

I've tried sending it a url of @"http:" but this doesn't work it changes pages to to "http:localhost/"

Is there a way to just Open it?

Plasma

Plasma
  • 2,622
  • 2
  • 20
  • 35
  • I don't plan to put this on the app store its for personal use, so if there is any undocumented api or a method to switch apps I'd be grateful of some help. – Plasma Jun 24 '12 at 13:53

2 Answers2

3

I solved this using the answers on this page ..

iOS How can I use UIApplication launchApplicationWithIdentifier which is in private APIs?

Though I didn't have to move my .app file in to /Applications

It was enough to add the entitlements, then simply call it using ...

[[UIApplication sharedApplication] launchApplicationWithIdentifier:@"com.apple.mobilesafari" suspended:NO];

Plasma

Community
  • 1
  • 1
Plasma
  • 2,622
  • 2
  • 20
  • 35
  • But does this require the device to be jailbroken? If not, does it work with the latest versions of iOS? – Dylan Nicholson Mar 31 '16 at 09:20
  • No it doesn't require a Jailbreak, and is fine to use as long as you don't plan to publish you app on the App Store, which I don't. – Plasma Mar 31 '16 at 18:13
0

Could you open to a page that executes JavaScript history.back() when loaded?

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • Its a good idea, but I think any new URL opened by the openURL method is in a new Tab hence "Back" would not work. But I will certainly look in to try this just in case it does work. – Plasma Jun 23 '12 at 22:01
  • Thinking along similar lines if I could open a new tab that automatically closes I might be on to a winner as it will fall back to the previous tab. Is there any way to programatically send it a page, or would it have to be a real url? – Plasma Jun 24 '12 at 10:39
  • Seems I can't close a window in this way, I've tried loads of methods but cannot get the window to close. Though I'll be the first to admit I'm not a stong html/java script programmer. At worst I can pop a page that says "Click Here To Close" but I can't even get that working! :( – Plasma Jun 24 '12 at 13:29