Search code examples
iosiphoneuiviewcontrollerios9sfsafariviewcontroller

In iOS 9, why is SFSafariViewController is being pushed instead of presented modally?


I'm presenting a SFSafariViewController by calling presentViewController:animated:completion: on a UIViewController instance.

The result is that it gets pushed on (slides in from the right), as if I called pushViewController:animated: on a UINavigationController instance. I've verified that this is all happening on the main queue. And the presenting view controller is not a modal itself (which shouldn't matter anyways, but just in case, we can rule that out).

If I substitute the SFSafariViewController with a UIViewController, it works as expected, it presents modally.

weakSelf.oAuthViewController = [[SFSafariViewController alloc] initWithURL:url];
[viewController presentViewController:weakSelf.oAuthViewController animated:YES completion:nil];

Any idea why or how to work around this?


Solution

  • Here's a simple way to obtain a vertical modal presentation of a SFSafariViewController:

    let safari = SFSafariViewController(URL: url)
    safari.modalPresentationStyle = .overFullScreen
    presentViewController(safari, animated: true, completion: nil)