J100
J100

Reputation: 4156

What is the default behaviour of 'Done' in SFSafariViewController?

I am using SFSafariViewController to display app-related information (e.g. About, Support, T&C) from websites via the Settings view.

In the Settings view, there is a table with static cells. After implementing the following codes in the Settings View Controller, a view that resembles the Safari browser appears and the URL provided was loaded properly.

    let url = URL(string: "https://google.com.au")
    let svc = SFSafariViewController(url: url!)
    self.present(svc, animated: true, completion: nil)

However, I didn't specify the action for the 'Done' button in the Navigation Bar. But it still dismissed the Safari browser view when it is tapped.

Question

Based on the tutorial here, I need to implement the SFSafariViewControllerDelegate protocol to dismiss the view controller.
I searched for some information in Apple's Documentation but couldn't find any information about the default behaviour for the 'Done' button.

  1. What is the default behaviour of the 'Done' button?
  2. Even though the 'Done' button is doing what I want it to (i.e. dismiss the view), should I still implement SFSafariViewControllerDelegate protocol?

Upvotes: 3

Views: 2391

Answers (1)

rounak
rounak

Reputation: 9387

If you see the documentation for the optional func safariViewControllerDidFinish(_ controller: SFSafariViewController) delegate method, the description says:

You can perform any necessary cleanup here. The view controller is dismissed afterwards.

Given that the done button works without adding the delegate along with the The view controller is dismissed afterwards. text in the description, I'd say it's safe to assume you don't need to implement the delegate if you're happy with the default Done behaviour.

More so the delegate method itself is optional, which is another indication that you don't need to implement the method.

Upvotes: 3

Related Questions