0

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;
}
locoboy
  • 38,002
  • 70
  • 184
  • 260

4 Answers4

1

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;
}
buczek
  • 2,011
  • 7
  • 29
  • 40
Ilya
  • 141
  • 1
  • 9
0

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;
    }
techloverr
  • 2,597
  • 1
  • 16
  • 28
0

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 :-

enter image description here

Badal Shah
  • 7,541
  • 2
  • 30
  • 65
0

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

Mugunth
  • 14,461
  • 15
  • 66
  • 94