WebViewProxy

@interface WebViewProxy : NSObject <UIWebViewDelegate>

@brief A class that intercepts and redirects calls from JS code running in a UIWebView to an object that will evaluate whether the call is a web page loading call or an invocation for a method in the native environment. The proxy object also allows calling a JS method in the web view from the native side.

  • A UIWebView instance

    Declaration

    Objective-C

    @property (assign, readwrite, atomic) UIWebView *webView;

    Swift

    var webView: UnsafeMutablePointer
  • Initialise a WebViewProxy object with a webview and a handler for invocation requests

    Declaration

    Objective-C

    - (id)initWithWebView:(UIWebView *)webView
        withInvocationHandler:(id<InvocationProcessor>)invocator;

    Swift

    init!(webView: Any!, withInvocationHandler invocator: InvocationProcessor!)

    Parameters

    webView

    a UIWebView instance

    invocator

    an object that implements the InvocationProcessor. This object will handle the invocation requests coming from the web view and call the appropriate method on the native side.

    Return Value

    a WebViewProxy instance.

  • Loads page from a given folder. Supports only simple file and folder names. Does not support name with folder path. Valid usage - loadPage:@index.html fromFolder:@www

    Declaration

    Objective-C

    - (void)loadPage:(NSString *)pageName fromFolder:(NSString *)folderName;

    Swift

    func loadPage(_ pageName: String!, fromFolder folderName: String!)

    Parameters

    pageName

    file name

    folderName

    folder name

  • Loads web page pointed to by URL in the UIWebView instance it holds a reference to.

    Declaration

    Objective-C

    - (void)loadUrl:(NSString *)url;

    Swift

    func loadUrl(_ url: String!)

    Parameters

    url

    a URL string.

  • create an NSError object.

    Declaration

    Objective-C

    - (void)createError:(NSError **)error
               withCode:(int)code
            withMessage:(NSString *)msg;

    Swift

    func createError(_ error: NSErrorPointer, withCode code: Int32, withMessage msg: String!)

    Parameters

    error

    error object

    code

    error code

    msg

    error message

  • Call a JS function on the webpage in the UIWebView instance.

    Declaration

    Objective-C

    - (void)callJSFunction:(NSString *)name withArgs:(NSDictionary *)args;

    Swift

    func callJSFunction(_ name: String!, withArgs args: [AnyHashable : Any]!)

    Parameters

    name

    JS function name

    args

    a dictionary of argument name-value pairs.