You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/06/28 00:47:01 UTC

ios commit: CB-11431 - Document ways to update delegates, preferences and script message handlers in WebViewEngines

Repository: cordova-ios
Updated Branches:
  refs/heads/master 7d993909d -> 3d80c24a5


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/3d80c24a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3d80c24a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3d80c24a

Branch: refs/heads/master
Commit: 3d80c24a594b4d43a368fa278a23218a3f17310f
Parents: 7d99390
Author: Shazron Abdullah <sh...@apache.org>
Authored: Mon Jun 27 17:48:35 2016 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Mon Jun 27 17:48:35 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/3d80c24a/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