WKWebView: build fail for iOS 10.2. XCode9 beta 6

We have previously used UIWebView, but since it is now marked as deprecated and is now available to be added to storyboard, we decided to use WKWebView, however when we use WKWebView, we are getting the following error:


error: Class Unavailable: WKWebView before iOS 11.0 (NSCoding support was broken in previous versions)


Once we change the target to iOS11 the build is successful. On Apple site it says that WKWebView should be used since iOS8.

Any help appreciated.

Thanks!

Replies

What is the 'Deployment' iOS setting for each target in that app's project?

Same problem here. In my case the error appears twice, setting the Deployment Target to 11.0 removes 1 of the errors the other remains.

I am using Xcode 9.0 beta 6 and they Deployment Target was originally set to 9.0.

Unfortunately this problem still persists in Xcode 9 GM!


I figure that any iOS 11 built App with WKWebView that has a target below iOS 11 will get this message. Basically this means that if you build an iOS 11 App with WKWebView, you can never set you deployment target to anything other than iOS 11, which is unacceptable.


@XcodeTeam ... please take a look at this!

I'm also experiencing this issue as well. It works if the deployment target is set to 11.0.

Same problem here

Having the exact same problem here with the GM release of Xcode 9... they need to fix this ASAP.

Did anyone found a solution? I am also stuck with the same problem :/

Stuck with the same issue :-(.

The issue is not fixed in the official relase of Xcode 9 yet, however, this is only an issue if you add a WKWebView in your storyboard. If you instead, create and add a WKWebView as a subview in code, everything will work just fine and you can target iOS versions below 11 (e.g. 10.x).

AFAIK,

This is only a problem if you are adding the WKWebView via IB.


If you add it programmaticly you should not have a problem

Same problem on Xcode 9.0 (9A235).

Class Unavailable: WKWebView before iOS 11.0 (NSCoding support was broken in previous versions)

Deployment target: 9.0

Same Problem here

Based on the message ("NSCoding support was broken in previous versions"),this does not appear to be an Xcode or IB/storyboard issue. The message suggests that the NSCoding protocol method -initWithCoder: was implemented incorrectly in pre-iOS 11 versions of WKWebView. That means that when a view controller containing a WKWebView in its hierarchy is loaded then your app may crash or behave incorrectly if it's not running on iOS 11 or later.


The implication is that if your deployment target is earlier than iOS 11 then you will need to create the WKWebView in code so that you're creating an instance using its designated initializer.

This answer is absolutely correct. It is in fact due a bug in WKWebView's -initWithCoder:, which is used to instantiate objects configured in Interface Builder. If this error had not been added, you would be able to build for earlier OS versions, but would get a runtime error when instantiating the WKWebView.


The workaround is to add the WKWebView in code in the meantime. Once your deployment target reaches iOS 11.0 (or macOS 10.13) or higher, IB will produce a warning to encourage migrating to WKWebView.

I tried the answer you shared on https://stackoverflow.com/questions/46221577/xcode-9-gm-wkwebview-nscoding-support-was-broken-in-previous-versions/46743021#46743021


However, it only works with a few websites. It does not work with my url, and for http://www.google.com too.

Any solution?