iOS应用程序可以在不打开页面的情况下切换到Safari?

我知道我的应用程序可以通过执行以下操作在Safari中打开特定的URL:

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

但是,有没有办法让我的应用程序切换到Safari, 而无需打开一个URL?

我想切换到Safari,但让它继续显示上次用户查看它打开的任何页面。

不幸的是没有,除非你能弄清楚如何在非越狱的环境中通过bundle id启动一个应用程序。

否则,如果您处于越狱环境,则可以使用以下命令通过其捆绑ID启动应用程序:

用法:

[self launch:(@"com.apple.mobilesafari")];

码:

 #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]; } } 

注意:

以这种方式启动应用程序基本上与在SpringBoard上的Safari图标点击相同。 这只会启动到应用程序,恢复以前活动的任何networking会话。