In cordova-ios-4.0, you would set the delegates of the webview through the webViewEngine
property of a CDVPlugin
or your CDVViewController
subclass.
There are constants in the CDVWebViewEngineProtocol
(which a webview-engine implements) that you can use to set the delegates and preferences. These values are the constants to be used when setting delegates or preferences in the UIWebView (default in cordova-ios-4.0) or the WKWebView (through installing the cordova-plugin-wkwebview-engine plugin). You can set one additional thing in the WKWebView, script message handlers.
For example, to set the UIWebViewDelegate
in your plugin code:
// your UIWebViewDelegate implementation reference
id< UIWebViewDelegate > myUIWebViewDelegate;
// set it
[self.webViewEngine updateWithInfo:@{
kCDVWebViewEngineUIWebViewDelegate : myUIWebViewDelegate
}]
For example, to set the webview preferences in your plugin code:
// put the preferences in a dictionary
NSDictionary* preferences = @{
@"EnableViewPortScale" : @YES,
@"AllowInlineMediaPlayback" : @NO
};
[self.webViewEngine updateWithInfo:@{
kCDVWebViewEngineWebViewPreferences : preferences
}]
If you are using the cordova-plugin-wkwebview-engine plugin, you can add a script message handler:
// your WKScriptMessageHandler implementation references
id< WKScriptMessageHandler > foo;
id< WKScriptMessageHandler > bar;
// put the handlers in a dictionary
NSDictionary* scriptMessageHandlers = @{
@"foo" : foo,
@"bar" : bar
};
[self.webViewEngine updateWithInfo:@{
kCDVWebViewEngineScriptMessageHandlers : scriptMessageHandlers
}]