ORAWebViewDelegate Class Reference

Inherits from NSObject
Conforms to UIWebViewDelegate
WKNavigationDelegate
Declared in ORAWebViewDelegate.h

Overview

WKWebview

Generating events through the JavaScript tag WKWebView/UIWebView embedded in a native app can generate events by using JavaScript helper methods that interact with the native app to generate and send events, or by using the JavaScript tag in the embedded web content to generate and send events. Follow these instructions to use the JavaScript tag. *

The native app must implement the Mobile Library for iOS, the web content must be tagged with the JavaScript tag, and you must be familiar with iOS WKWebView/UIWebView. *

If we don't need to do any web view delegation of our own, we'll simply create a retained instance of ORAWebViewDelegate and let it do the work for us

There are two methods (WKWebView andUIWebView ) of alerting the Data Collector of JavaScript-triggered events.

The first is using the supplied ORAWebViewDelegate, shown here:

Method 1 – supplied delegate

(void)viewDidLoad {
    [super viewDidLoad];
    NSURL *url = [NSURL URLWithString:@"https://bank.wt-go.com/invest"];

   // If you want to share a session between the app and the website,
   // append it to the URL before triggering the request
   // using the appendSessionParamsToUrl: method below
   NSURL *sessionedUrl = [[ORADataCollector sharedCollector] appendSessionParamsToUrl:url];
   self.wtDelegate = [ORAUIWebViewDelegate new];

   // Set our retained ORAWebViewDelegate as the UIWebView's delegate
   self.wkWebView.navigationDelegate = self.wtDelegate;
   [self.wkWebView loadRequest:[NSURLRequest requestWithURL:sessionedUrl]];
 }

Method 2 – Self-supplied delegate

When using WKWebview, conform to WKNavigationDelegate, and implement -webView:decidePolicyForNavigationAction:decisionHandler:

(void)viewDidLoad {
   [super viewDidLoad];
   NSURL *url = [NSURL URLWithString:@"https://bank.wt-go.com/invest"];

   // If you want to share a session between the app and the website,
   // append it to the URL before triggering the request
   // using the appendSessionParamsToUrl: method below
    NSURL *sessionedUrl = [[ORADataCollector sharedCollector] appendSessionParamsToUrl:url];
    self.wtDelegate = [ORAUIWebViewDelegate new];

   // Set our retained ORAWebViewDelegate as the UIWebView's delegate
    self.wkWebView.navigationDelegate = self.wtDelegate;
    [self.wkWebView loadRequest:[NSURLRequest requestWithURL:sessionedUrl]];
 }

Include the following inside your method:

(void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
     BOOL shouldStart = [ORAWebViewDelegate shouldStartLoadWithRequest:navigationAction.request];
     if (!shouldStart) {
      decisionHandler(WKNavigationActionPolicyCancel);
       return;
   }
 // Any custom decision policy code
 }

UIWebView

The first is using the supplied ORAWebViewDelegate, shown here:

Method 1 – supplied delegate

(void)viewDidLoad {
   [super viewDidLoad];
  NSURL *url = [NSURL URLWithString:@"https://bank.wt-go.com/invest"];

   // If we want to share a session between the app and the website,
   // we'll append it to the URL before triggering the request
   // using the appendSessionParamsToUrl: method below
   NSURL *sessionedUrl = [[ORADataCollector sharedCollector] appendSessionParamsToUrl:url];

   // Set our retained ORAWebViewDelegate as the UIWebView's delegate
   self.webView.delegate = self.wtDelegate;
   [self.webView loadRequest:[NSURLRequest requestWithURL:sessionedUrl]];
 }

If we need our own web view delegation methods, we'd mark ourself as the delegate as follows.

Method 2 – Self-supplied delegate

(void)viewDidLoad {
   [super viewDidLoad];
   NSURL *url = [NSURL URLWithString:@"https://bank.wt-go.com/invest"];

  // If we want to share a session between the app and the website,
  // we'll append it to the URL before triggering the request
  // using the appendSessionParamsToUrl: method below
  NSURL *sessionedUrl = [[ORADataCollector sharedCollector] appendSessionParamsToUrl:url];
  // If we do this, we must implement webView:ShouldStartLoadWithRequest:navigationType
  self.webView.delegate = self;
  [self.webView loadRequest:[NSURLRequest requestWithURL:sessionedUrl]];
 }

This method must be present if we're not using a retained instance of ORAWebViewDelegate // as our delegate, otherwise the app won't be able to see JavaScript-triggered events

  (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
    {
      if (![ORAWebViewDelegate shouldStartLoadWithRequest:request]) {
      return NO;
      }
      //Any custom logic here
      return YES;
    }