简体   繁体   中英

Appdelegate presentviewcontroller

I'm trying to display the webpage google.com using the following. For some reason it's not presenting the controller with google.com. Can anyone help?

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

I think this should work:

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

try this

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

How to use SFSafariview controller first check on this link.

SFSafariViewController

Moreover you can check full tutorial in below link also,

Example 1 :- iOS-SafariViewControllerFinishedProject

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

From github you can also download Demo Project. IOS9SafariViewControllerTutorial Example

Edit :-

I have make demo for you without storyboard . please check on below link.

Safari without storyboard demo

Output :-

在此处输入图片说明

Move the SafariViewController presentation code to viewDidAppear of your RootViewController . If your RootViewController is a UINavigationController , move it to the viewDidAppear of your Navigation Controller's topViewController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM