I know that my app can open a particular URL in Safari by doing something like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.example.com/"]];
but, is there any way to have my app switch over to Safari without opening a URL?
I'd like to switch to Safari, but let it keep showing whatever page it had open the last time the user looked at it.
Unfortunately no, unless you can figure out how to launch an app by bundle id in a non-jailbroken environment.
Otherwise, if you are in a jailbroken environment, you can use the following to launch an app by its bundle id:
Usage:
[self launch:(@"com.apple.mobilesafari")];
Code:
#pragma mark - Launch Application
-(void)launch:(NSString *)bundle {
Class SBApplicationController = objc_getClass("SBApplicationController");
id appController = [SBApplicationController sharedInstance];
NSArray *apps = [appController applicationsWithBundleIdentifier: bundle];
if ([apps count] > 0) {
//Wait .5 seconds.. then launch.
[self performSelector:@selector(launchTheApp:) withObject:[apps objectAtIndex:0] afterDelay: 0.5];
} else {
id app = [appController applicationWithDisplayIdentifier: bundle];
if (app) {
//Wait .5 seconds.. then launch.
[self performSelector:@selector(launchTheApp:) withObject:app afterDelay: 0.5];
}
}
}
-(void)launchTheApp:(id)app {
Class SBUIController = objc_getClass("SBUIController");
id uiController = [SBUIController sharedInstance];
if([uiController respondsToSelector:@selector(animateLaunchApplication:)]) {
[uiController animateLaunchApplication:app animateDefaultImage:YES];
} else {
[uiController activateApplicationAnimated:app];
}
}
Note:
Launching the app this way is basically the same as tapping on the Safari icon in SpringBoard. This will only launch into the app, resuming any web session that was previously active.