Akshat Akshat - 8 months ago 45
iOS Question

Conditional subclassing based on iOS version

This may be slightly odd to ask, is there a way to conditionally subclass based on iOS version, essentially:

if(iOS version >= 9) {
@interface CDVWKWebViewEngine : CDVPlugin <CDVWebViewEngineProtocol, WKScriptMessageHandler, WKNavigationDelegate>
} else if(iOS version = 8) {
@interface CDVWKWebViewEngine : CDVPlugin <WKScriptMessageHandler, WKNavigationDelegate>

I have the iOS Cordova WkWebView Engine plugin and would like to fall back to the UIWebView under iOS 8 (ignore the plugin on iOS 8).

I've found it rather tricky to make the use of this plugin conditional as it is so deeply entrenched into the project once it subclasses the UIWebView default plugin.


There are preprocessor macros defined for different versions

// code to compile for iOS 9 or greater
// code to compile for les than iOS 9