Mobile SDK iOS: EPZPromoWebViewController
From ePrize Developers Wiki
(Initial authoring) |
m (Minor formatting updates) |
||
Line 76: | Line 76: | ||
- | + | <hr/> | |
=== promoWebViewControllerWithURL:options: === | === promoWebViewControllerWithURL:options: === | ||
Line 153: | Line 153: | ||
- | + | <hr/> | |
=== initWithURL:options: === | === initWithURL:options: === |
Current revision
Contents |
Overview
The EPZPromoWebViewController class controls the SDK’s built-in web view. To use, you will need to create an instance of this class, and initialize with a promotion configuration key or URL.
Creating a View
To create an instance of EPZPromoWebViewController and add it to your application, you can use code like the following. Note that "config" makes use of the sharedLibrary for both retrieval of a configuration object, and the configuration key used to retrieve this configuration object.
// Get first promotion configuration object EPZPromoConfiguration *config = [[EPZPromoLibrary sharedLibrary] promotionConfigurationForKey:[[[EPZPromoLibrary sharedLibrary] promoKeys] objectAtIndex:0]]; // Create instance of the view controller EPZPromoWebViewController *pvc = [[EPZPromoWebViewController alloc] initWithPromoConfigKey:config.configKey options:nil]; // Set delegate pvc.delegate = self; // Present view controller [self presentViewController:pvc animated:YES completion:nil];
Tasks
Setting and Getting the Delegate
delegate property
Initializing
+ promoWebViewControllerWithPromoConfigKey:options:
+ promoWebViewControllerWithURL:options:
- initWithPromoConfigKey:options:
- initWithURL:options:
Properties
delegate
The receiver's delegate.
@property (nonatomic, assign) id <EPZPromoWebViewControllerDelegate> delegate
Discussion
The delegate is sent messages when the view is created, as well as when it is targeted to close. See EPZPromoWebViewControllerDelegate for methods this delegate implements.
Declared In
EPZPromoWebViewController.h
Class Methods
promoWebViewControllerWithPromoConfigKey:options:
Initializes and returns a newly allocated view object with the specified items from the options.
+ (EPZPromoWebViewController *) promoWebViewControllerWithPromoConfigKey:(NSString *)key options:(NSDictionary *)options
Parameters
- key
- The promotion configuration key for the target promotion you wish to show in the view. Promotion configuration keys are stored in the sharedLibrary promoKeys array, and are properties of all instances of EPZPromoConfiguration included in the sharedLibrary promoConfigurations object.
Note: This must be a valid configuration key for a promotion to be successfully loaded. If an invalid key is passed, the view will still be created and returned, but a blank web view will be seen.
- options
- A dictionary of optional elements to use for styling the toolbar (and enclosed elements) in the view. This dictionary has the same keys specified in the initWithPromoConfigKey:options: method.
Discussion
This method returns an initialized instance of EPZPromoWebViewController. Once initialized, this view loads the endpointURL value for the specified promotion configuration key into an instance of EPZWebView. The toolbar and its enclosed elements provide the user ways to close the view, refresh a web page, and navigate back and forward in the web page (when applicable).
This view is designed to fill the entire screen of the application, and has appropriate logic to allow for filling the screen even when the device is rotated.
Note: There is intentionally no visible address bar in this view, thus preventing a user from navigating away from the intended web page (and its own internal web links).
See Also
initWithPromoConfigKey:options:
Declared In
EPZPromoWebViewController.h
promoWebViewControllerWithURL:options:
Returns a newly allocated and initialized view object with the specified items from the options.
+ (EPZPromoWebViewController *) promoWebViewControllerWithURL:(NSString *)url options:(NSDictionary *)options
Parameters
- url
- The URL for the web page you wish to show in the view.
- options
- A dictionary of optional elements to use for styling the toolbar (and enclosed elements) in the view. This dictionary has the same keys specified in the initWithPromoConfigKey:options: method.
Discussion
This is a convenience method that returns an initialized instance of EPZPromoWebViewController. Once initialized, this view loads the URL into an instance of EPZWebView. The toolbar and its enclosed elements provide the user ways to close the view, refresh a web page, and navigate back and forward in the web page (when applicable).
This view is designed to fill the entire screen of the application, and has appropriate logic to allow for filling the screen even when the device is rotated.
Note: There is intentionally no visible address bar in this view, thus preventing a user from navigating away from the intended web page (and its own internal web links).
See Also
initWithURL:options:
Declared In
EPZPromoWebViewController.h
Instance Methods
initWithPromoConfigKey:options:
Initializes and returns a newly allocated view object with the specified items from the options.
- (id) initWithPromoConfigKey:(NSString *)key options:(NSDictionary *)options
Parameters
- key
- The promotion configuration key for the target promotion you wish to show in the view. Promotion configuration keys are stored in the sharedLibrary promoKeys array, and are properties of all instances of EPZPromoConfiguration included in the sharedLibrary promoConfigurations object.
Note: This must be a valid configuration key for a promotion to be successfully loaded. If an invalid key is passed, the view will still be created and returned, but a blank web view will be seen.
- options
- A dictionary of optional elements to use for styling the toolbar (and enclosed elements) in the view. If this value is nil, default values will be used for all stylized elements of the web view. Below is a list of all valid elements that can be included in the options dictionary, listed by their dictionary key and the type of class each item must be. Each item includes a short description and its default value.
- toolBar (UIToolbar) - The toolbar used at the bottom of the view. The toolbar must be 44px tall. If this value varies, you may experience unexpected results in the display.
- Default: UIToolbar with barStyle of UIBarStyleBlackOpaque
- toolBar (UIToolbar) - The toolbar used at the bottom of the view. The toolbar must be 44px tall. If this value varies, you may experience unexpected results in the display.
- closeButton (UIBarButtonItem) - The close button used to close the view.
- Default: A UIBarButtonItemStyleBordered with label "Close"
- closeButton (UIBarButtonItem) - The close button used to close the view.
- refreshButton (UIBarButtonItem) - The refresh button used to refresh the web page loaded in the view's web view.
- Default: UIBarButtonSystemItemRefresh
- refreshButton (UIBarButtonItem) - The refresh button used to refresh the web page loaded in the view's web view.
- backButton (UIBarButtonItem) - The back button used navigate back to the previous page in the view's web view.
- Default: An inverted instance of UIBarButtonSystemItemPlay
- backButton (UIBarButtonItem) - The back button used navigate back to the previous page in the view's web view.
- forwardButton (UIBarButtonItem) - The forward button used navigate back to the previous page in the view's web view.
- Default: UIBarButtonSystemItemPlay
- forwardButton (UIBarButtonItem) - The forward button used navigate back to the previous page in the view's web view.
- tintColor (UIColor) - A tint color to apply to the toolbar.
- Default: None (no tint color applied)
- tintColor (UIColor) - A tint color to apply to the toolbar.
Discussion
This method initializes and returns an instance of EPZPromoWebViewController. Once initialized, this view loads the endpointURL value for the specified promotion configuration key into an instance of EPZWebView. The toolbar and its enclosed elements provide the user ways to close the view, refresh a web page, and navigate back and forward in the web page (when applicable).
This view is designed to fill the entire screen of the application, and has appropriate logic to allow for filling the screen even when the device is rotated.
Note: There is intentionally no visible address bar in this view, thus preventing a user from navigating away from the intended web page (and its own internal web links).
See Also
promoWebViewControllerWithPromoConfigKey:options:
Declared In
EPZPromoWebViewController.h
initWithURL:options:
Initializes and returns a newly allocated view object with the specified items from the options.
- (id) initWithURL:(NSString *)url options:(NSDictionary *)options
Parameters
- url
- The URL for the web page you wish to show in the view.
- options
- A dictionary of optional elements to use for styling the toolbar (and enclosed elements) in the view. This dictionary has the same keys specified above in the initWithPromoConfigKey:options: method.
Discussion
This method initializes and returns an instance of EPZPromoWebViewController. Once initialized, this view loads the URL into an instance of EPZWebView. The toolbar and its enclosed elements provide the user ways to close the view, refresh a web page, and navigate back and forward in the web page (when applicable).
This view is designed to fill the entire screen of the application, and has appropriate logic to allow for filling the screen even when the device is rotated.
Note: There is intentionally no visible address bar in this view, thus preventing a user from navigating away from the intended web page (and its own internal web links).
See Also
promoWebViewControllerWithURL:options:
Declared In
EPZPromoWebViewController.h
MobileSDK JavaScript Bridge
The EPZPromoWebViewController comes equipped with the ability to inject a JavaScript object named MobileSDK if one is not found in the web page that is loaded into the web view. The MobileSDK JavaScript object is set up to be publicly accessible to any web page loaded into the EPZPromoWebViewController, and includes the functions listed below. The EPZPromoWebViewController contains the necessary logic to handle these functions and react accordingly, dispatching the promoWebView:didFireEvent:withData: delegate method.
Functions
trackEvent(eventName, data)
This function tracks an event with the event name (String) and data (Object) specified, which is caught by the EPZPromoWebViewController and dispatched to the parent application to handle as needed.
- Sample Usage:
MobileSDK.trackEvent('saveUserEmail', {"email": document.getElementById("email").value});
syncEvents()
This function is a convenience function that loops through any queued events that have not been dispatched up to the EPZPromoWebViewController. An event is only queued when the MobileSDK JavaScript object is not yet initialized (this is a rare instance).
- Sample Usage:
MobileSDK.syncEvents();