cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [04/12] ios commit: CB-11431 - Document ways to update delegates, preferences and script message handlers in WebViewEngines
Date Wed, 27 Jul 2016 01:04:23 GMT
CB-11431 - Document ways to update delegates, preferences and script message handlers in WebViewEngines


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/d536d8c7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/d536d8c7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/d536d8c7

Branch: refs/heads/4.2.x
Commit: d536d8c74394b1e38ac48fc2f8a010670ec85256
Parents: c994442
Author: Shazron Abdullah <shazron@apache.org>
Authored: Mon Jun 27 17:48:35 2016 -0700
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Tue Jul 26 16:24:41 2016 -0700

----------------------------------------------------------------------
 ...nd Script Message Handlers in the WebView.md | 51 ++++++++++++++++++++
 1 file changed, 51 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/d536d8c7/guides/Setting Delegates,
Preferences and Script Message Handlers in the WebView.md
----------------------------------------------------------------------
diff --git a/guides/Setting Delegates, Preferences and Script Message Handlers in the WebView.md
b/guides/Setting Delegates, Preferences and Script Message Handlers in the WebView.md
new file mode 100644
index 0000000..945ce3d
--- /dev/null
+++ b/guides/Setting Delegates, Preferences and Script Message Handlers in the WebView.md

@@ -0,0 +1,51 @@
+# Setting Delegates, Preferences and Script Message Handlers in the WebView
+
+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`](https://github.com/apache/cordova-ios/blob/master/CordovaLib/Classes/Public/CDVWebViewEngineProtocol.h#L22-L26)
(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](https://github.com/apache/cordova-plugin-wkwebview-engine)
plugin). You can set one additional thing in the WKWebView, [script message handlers](https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKScriptMessageHandler_Ref/).
+
+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](https://github.com/apache/cordova-plugin-wkwebview-engine)
plugin, you can add a [script message handler](https://developer.apple.com/library/ios/documentation/WebKit/Reference/WKScriptMessageHandler_Ref/):
+```
+// 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
+}]
+```
+
+
+
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message