0

I'm encountering a very strange issue while trying to migrate from my custom web view controller which was using WKWebView to SFSafariViewController.

With a debugger attached, on a simulator or device, when I present an SFSafariViewController, everything works as expected:

enter image description here

However, when the debugger is detached, on a simulator or device, the layout breaks and the content never loads:

enter image description here

The code in both cases is exactly the same:

func presentWebViewController(for url: URL) {
    let safariViewController = SFSafariViewController(url: url)
    self.present(safariViewController, animated: true, completion: nil)
}

Have you ever encountered this issue before? I'm running iOS 15 / Xcode 13 if that helps.

Logan Shire
  • 5,013
  • 4
  • 29
  • 37
  • Update: I've determined that *something* in my project is breaking it by testing with a clean project and being unable to repro. I'll have to go through and bisect my dependencies to figure out what's breaking it. I suspect Firebase or something else is Swizzling a method on it and breaking something. Will report back when I have an update. – Logan Shire Sep 29 '21 at 06:45

1 Answers1

0

Okay, I finally pinned it down. After a lot of trial and error, the issue seemed to be this extension I had on UIViewController. I wrote this so that I could provide lifecycle methods on my view controller(s) corresponding to the UIView willMove(to:) and didMove(to:) methods. My guess is that Apple or the Safari Services framework has a method with an identical name and my implementation was shadowing that. Once I changed the names of these methods, it started working again.

extension UIViewController {

    /**
     The view will move to or from a window.
     */
    @objc
    open func viewWillMove(toWindow newWindow: UIWindow?) {}

    /**
     The view did move to or from a window.
     */
    @objc
    open func viewDidMoveToWindow() {}
}
Logan Shire
  • 5,013
  • 4
  • 29
  • 37