Appdelegate presentviewcontroller

问题描述 投票:0回答:4

我正在尝试使用以下内容显示网页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;
}
ios rootviewcontroller
4个回答
1
投票

我认为这应该有效:

- (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;
}

0
投票

试试这个

 - (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;
    }

0
投票

如何使用SFSafariview控制器首先检查此链接。

SFSafariViewController

此外,您还可以查看以下链接中的完整教程,

例1: - iOS-SafariViewControllerFinishedProject

例2: - ios-9-getting-started-with-sfsafariviewcontroller

从github您还可以下载Demo Project。 IOS9SafariViewControllerTutorial Example

编辑: -

我没有故事板为你制作演示。请查看以下链接。

Safari without storyboard demo

输出: -

enter image description here


0
投票

SafariViewController演示代码移动到viewDidAppearRootViewController。如果您的RootViewControllerUINavigationController,请将其移至导航控制器的viewDidAppeartopViewController

© www.soinside.com 2019 - 2024. All rights reserved.