1

With the recent update on Xcode 9 Beta and iOS11 preview, there are some changes to SFSafariViewController init methods.

@available(iOS 11.0, *)
public init(url URL: URL, configuration: SFSafariViewController.Configuration)

@available(iOS, introduced: 9.0, deprecated: 11.0)
public convenience init(url URL: URL, entersReaderIfAvailable: Bool)

There is one new init method that is supported from iOS11 onwards while the currently available init method will be deprecated by iOS11. The problem is that the current method is not exposed and could not be overwritten. This forces the use of the new init method if we want to use the beta to run the existing project. Has anyone found a way to use the existing init method in the new Xcode Beta?

Edit: For clarification, this is a snippet of the init method in my subclass

class BPSafariViewController: SFSafariViewController {
    override init(url URL: URL, entersReaderIfAvailable: Bool) {
        super.init(url: URL, entersReaderIfAvailable: entersReaderIfAvailable)
        if #available(iOS 10.0, *) {
            preferredControlTintColor = UIColor.BPUIColor()
        } else {
            view.tintColor = UIColor.BPUIColor()
        }
    }
}
John Kuan
  • 116
  • 2
  • 11

3 Answers3

1

You can do that while checking the iOS version as below.

var safariController: SFSafariViewController?
if #available(iOS 11.0, *) {
    safariController = SFSafariViewController(url: URL(string: "your_url")!)
} else {
    safariController = SFSafariViewController(url: URL(string: "")!, entersReaderIfAvailable: true)
}
Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57
  • Hi Sohil. Thanks for your answer. I am using the init method as an override for a SFSafariViewController subclass. – John Kuan Jun 13 '17 at 10:34
  • @JohnKuan This is the `init` itself. What error are you facing above? – Sohil R. Memon Jun 13 '17 at 10:37
  • I am using an existing subclass of SFSafariViewController hence I require the override method available. The problem is this `init` method has been marked for deprecation and I had to use another `init`. – John Kuan Jun 14 '17 at 06:46
1

Change deprecated function:

super.init(url: url, entersReaderIfAvailable: true) 

to:

let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
    
super.init(url: url, configuration: config)
Steve
  • 213,761
  • 22
  • 232
  • 286
0

I have found a possible solution relying on another convenience method. Although I cannot use entersReaderIfAvailable option, it works for my app for now.

convenience init(url URL: URL) {
    self.init(url: URL)
    //code
}
John Kuan
  • 116
  • 2
  • 11