Mobile SDK iOS: EPZWebViewDelegate
From ePrize Developers Wiki
(Initial authoring.) |
m (Minor formatting updates) |
||
Line 31: | Line 31: | ||
- | + | <hr/> | |
=== webViewDidFinishLoad: === | === webViewDidFinishLoad: === | ||
Line 50: | Line 50: | ||
- | + | <hr/> | |
=== webView:didFailLoadWithError: === | === webView:didFailLoadWithError: === | ||
Line 71: | Line 71: | ||
- | + | <hr/> | |
=== webView:didFireEvent:withData: === | === webView:didFireEvent:withData: === |
Current revision
Contents |
Overview
The EPZWebViewDelegate protocol defines methods that a delegate of EPZWebView can implement to handle actions pertaining to interactions with the class methods.
Tasks
- webViewDidStartLoad: optional method
- webViewDidFinishLoad: optional method
- webView:didFailLoadWithError: optional method
- webView:didFireEvent:withData: optional method
Instance Methods
webViewDidStartLoad:
Dispatched when the web view starts loading content.
- (void) webViewDidStartLoad:(EPZWebView *)webView
Parameters
- webView
- The instance of EPZWebView that dispatched the method.
Discussion
The delegate responds to the web view starting to load content.
Declared In
EPZWebViewDelegate.h
webViewDidFinishLoad:
Dispatched when the web view finishes loading content.
- (void) webViewDidFinishLoad:(EPZWebView *)webView
Parameters
- webView
- The instance of EPZWebView that dispatched the method.
Discussion
The delegate responds to the web view finishing loading content.
Declared In
EPZWebViewDelegate.h
webView:didFailLoadWithError:
Dispatched when the web view failed to load content.
- (void) webView:(EPZWebView *)webView didFailLoadWithError:(NSError *)error
Parameters
- webView
- The instance of EPZWebView that dispatched the method.
- error
- NSError object with details of the error.
Discussion
The delegate responds to the web view encountering an error loading the specified content.
Declared In
EPZWebViewDelegate.h
webView:didFireEvent:withData:
Dispatched when the EPZWebView receives an event from the web page loaded into its web view.
- (void) webView:(EPZWebView *)webView didFireEvent:(NSString *)eventName withData:(NSDictionary *)data
Parameters
- webView
- The instance of EPZWebView that dispatched the method.
- eventName
- The event name triggered. Presently there are no set values for this parameter.
- data
- A dictionary object with additional event data, if any. Presently there are no set values for dictionary key/value pairs, as they originate from the web page, not the SDK's web view.
Discussion
The delegate responds to an event being triggered from the web view, which catches it from a web page it contains. This method can be used to respond to events and have the parent app act accordingly (e.g. store user information passed in an event, etc.).
Important Note: Since there are no standard set of events, nor are there standard event data key/value pairs, it is ultimately the responsibility of your application to handle the event and react accordingly, including any necessary logic to check for event names and data key/value pairs, as seen in the code example below.
Event Handling Example
If your company plans to run promotions in which you would like to pass a user email address from the web page into the app, you would have the promotion web page call the trackEvent(eventName, data) function on the MobileSDK JavaScript Object, like so:
// JavaScript MobileSDK.trackEvent('saveUserEmail', {"email": document.getElementById("email").value});
Then in your mobile application, you would include logic to search the event data for an "email" key/value pair, and store it as needed.
- (void) webView:(EPZWebView *)webView didFireEvent:(NSString *)eventName withData:(NSDictionary *)data { [data objectForKey:@"email"] if ([eventName isEqualToString:@"saveUserEmail"] && userEmail != nil) { // Store user email as needed } }
Declared In
EPZWebViewDelegate.h