Re: How to present a web view while supporting 10.9?


Sandor Szatmari
 

What SDK are you building against?
I assuming deployment target of 10.9 and not earlier…

What is the exact problem your having? Is it just warnings, or are there compile/link/runtime errors…

I just set the deployment target of an app with a WKWebView to 10.9 and build SDK 10.14. I got warnings of WKWebview et. all… not being available on 10.9 but it compiled and ran fine on Mojave. I’m assuming the availability conditionals would allow selection of WebView code if I ran it on some earlier release.

I added a reference to a plain WebView and it did not complain about that with the deployment target set to 10.9.

Sandor


On Feb 6, 2020, at 08:07, John Brownie <john_brownie@sil.org> wrote:

My app currently supports 10.9, and I want to add a feature that displays an HTML document stored locally (in the bundle). The obvious way is to have a window which contains a web view. However, WKWebView is only available in 10.10, and WebView is deprecated.

If it were a matter of calling a method, I could wrap it with availability calls, but it's a definition of the class of an element in a window controller class. Presumably there is a way to handle this, but I haven't discovered it.

What I'm looking for is something like

if #available(macOS 10.10, *) {
var webView: WKWebView
}
else {
var webView: WebView
}

...but that is for running code, not declarations.

Is there a way to do this through IB? Or is my alternative to build the window in code, using whatever is available based on the runtime platform?

John
--
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland


Join cocoa@apple-dev.groups.io to automatically receive all group messages.