iOS App可以在不打开页面的情况下切换到Safari吗? [英] Can an iOS App Switch to Safari Without Opening a Page?

查看:257
本文介绍了iOS App可以在不打开页面的情况下切换到Safari吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我的应用可以通过以下方式打开Safari中的特定网址:

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/"]];

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

but, is there any way to have my app switch over to Safari without opening a URL?

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

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.

推荐答案

不幸的是,除非你能弄清楚如何在非越狱环境中通过捆绑包ID启动应用程序。

Unfortunately no, unless you can figure out how to launch an app by bundle id in a non-jailbroken environment.

否则,如果您处于越狱环境中,您可以使用以下内容通过其包ID启动应用程序:

Otherwise, if you are in a jailbroken environment, you can use the following to launch an app by its bundle 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图标基本相同。这只会启动到应用程序中,恢复之前处于活动状态的任何网络会话。

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.

这篇关于iOS App可以在不打开页面的情况下切换到Safari吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆