UAJavaScriptDelegate Protocol Reference
Conforms to | NSObject |
Declared in | UAJavaScriptDelegate.h |
Overview
A standard protocol for accessing native Objective-C functionality from webview content.
UADefaultJSDelegate is a reference implementation of this protocol.
Instance Methods
callWithData:withCompletionHandler:
Delegates must implement this method. Implementations take a model object representing call data, which includes the command name, an array of string arguments, and a dictionary of key-value pairs (all strings). After processing them, they pass a string containing Javascript that will be evaluated in a message’s UIWebView.
- (void)callWithData:(UAWebViewCallData *)data withCompletionHandler:(UAJavaScriptDelegateCompletionHandler)completionHandler
Parameters
- data
An instance of
UAWebViewCallData
- completionHandler
A completion handler to be called with the resulting string to be executed back in the JS environment.
Discussion
If the passed command name is not one the delegate responds to, or if no JavaScript side effect is desired, it implementations should pass nil.
To pass information to the delegate from a webview, insert links with a “uairship” scheme, args in the path and key-value option pairs in the query string. The host portion of the URL is treated as the command name.
The basic URL format:
uairship://command-name/
For example, to invoke a command named “foo”, and pass in three args (arg1, arg2 and arg3) and three key-value options {option1:one, option2:two, option3:three}:
uairship://foo/arg1/arg2/arg3?option1=one&option2=two&option3=three
The default, internal implementation of this protocol is UAActionJSDelegate. UAActionJSDelegate reserves command names associated with running Actions, and handles those commands exclusively.
Declared In
UAJavaScriptDelegate.h