Mike Purcell Mike Purcell - 5 months ago 38
Swift Question

ios9 - Swift 2.1 - SFSafariViewController

I'm looking to use the SFSafariViewController and have it automatically load a website when the app is opened. Is this possible?

What I have so far (brand new single ios app):

// ViewController.swift
let urlString = "https://stackoverflow.com"

@IBAction func launchSFSafariViewController(sender: AnyObject) {
if let url = NSURL(string: urlString) {
let vc = SFSafariViewController(URL: url, entersReaderIfAvailable: true)
vc.delegate = self

presentViewController(vc, animated: true, completion: nil)

How do I connect the action to the main view controller via the storyboard? All the articles I see only discuss connecting a button to an action.


Implement viewDidAppear to perform the presentation. (You will need to use a Bool flag, though, to make sure this doesn't happen when you dismiss the presented view controller and viewDidAppear is called again!)