I'm using SFSafariViewController in an iOS 9 app I'm building using Swift 2.
I am trying to open a URL which fails for some reason. EVery other URL I've tried works, except for this one:
http://www.ctvnews.ca/sci-tech/33-engineers-to-be-recognized-at-sci-tech-oscars-1.2730223
The URL is fine in regular mobile Safari in the simulator, on my iPhone, my iPad, and in any desktop browser. It is just when I try accessing it via Swift in this app that it fails.
Code is as follows:
func openInSafari(URLtoOpen: String) {
print("Trying to openURL: " + URLtoOpen)
let safariVC = SFSafariViewController(URL:NSURL(string: URLtoOpen)!, entersReaderIfAvailable: false)
safariVC.delegate = self
self.presentViewController(safariVC, animated: true, completion: nil)
}
func safariViewController(controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
// SFSafariViewController will present an error message in the browser,
// but in this case we will dismiss the view controller and present our
// own error alert.
if didLoadSuccessfully == false {
controller.dismissViewControllerAnimated(true, completion: { [unowned self] () -> Void in
let alert = UIAlertController(title: "Could Not Load", message: "The URL could not be loaded.", preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
})
}
}
This code works fine, and, as I said, other URLs load just fine. What I really need is just a way to more verbosely debug what safariViewController is encountering that is causing it to fail.
The didLoadSuccessfully == false
line doesn't really appear to offer much more debugging options to get a sense of what went wrong.
In other words, how do I debug this? I can't seem to find anything in Apple's docs that would explain what to check in case of a loading error.
Please help! Thanks.