我正在尝试使用以下内容显示网页google.com。出于某种原因,它不会通过google.com呈现控制器。有人可以帮忙吗?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com"]];
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:vc animated:YES completion:nil];
return YES;
}
我认为这应该有效:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com"]];
self.window.rootViewController = vc;
return YES;
}
试试这个
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SFSafariViewController *vc = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.google.com"]];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
如何使用SFSafariview控制器首先检查此链接。
此外,您还可以查看以下链接中的完整教程,
例1: - iOS-SafariViewControllerFinishedProject
例2: - ios-9-getting-started-with-sfsafariviewcontroller
从github您还可以下载Demo Project。 IOS9SafariViewControllerTutorial Example
编辑: -
我没有故事板为你制作演示。请查看以下链接。
Safari without storyboard demo
输出: -
将SafariViewController
演示代码移动到viewDidAppear
的RootViewController
。如果您的RootViewController
是UINavigationController
,请将其移至导航控制器的viewDidAppear
的topViewController