Mobile SDK iOS

From ePrize Developers Wiki

(Difference between revisions)
Jump to: navigation, search
(Adding EPZConstants section. Also removing links from within pre tags which were not being honored.)
(Complete overhaul for v2.0 of the SDK.)
Line 1: Line 1:
== OS Support ==
== OS Support ==
-
The ePrize Mobile SDK is built for iOS apps targeting <b>iOS 5 and higher. </b>
+
The HelloWorld Mobile SDK is built for iOS apps targeting <b>iOS 6 and higher. </b>
-
== Getting Started ==
+
== Version & Release Notes ==
-
The ePrize Mobile SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with ePrize, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.
+
<b>SDK Version:</b> 2.0
-
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Please note:</b> Using this SDK requires a valid client key provided by ePrize. If you do not have a client key, please contact your account team or Producer.</i></div>
+
<b>Release Notes:</b>
-
=== Key Concepts ===
+
* Integration with push notifications
 +
** Subscribe and unsubscribe from push notifications
 +
** Fetch, set, and save push notification preferences for specific users (including built-in Push Preferences view controller)
 +
** Record actions for specific push notifications
 +
* Analytics tracking events
 +
** Queue analytics events to be tracked with the SDK’s Analytics Service, complete with custom data, if desired
 +
* Web View Event Handling
 +
** Improved integration with web pages loaded into the built-in web view controller, using the HelloWorld MobileSDK JavaScript bridge, allowing correctly-configured events fired off from a web page to bubble up through the SDK and dispatched to the parent app.
 +
* Improved event dispatching
 +
** Delegate (and methods) in Singleton classes replaced with block callbacks
-
<b>Shared Library</b><br />
+
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Note on naming:</b> You will notice that the SDK uses the historical company name “ePrize” in the framework name, and “EPZ” for the class namespace. Future releases of the SDK may include updates to these names and namespaces to reflect the new company name, HelloWorld, which was introduced in 2014. </i></div>
-
This SDK has a class named [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]], which is a Singleton class that is the workhorse of the SDK. Since it is a Singleton, you will not create instances of it, but rather, will simply reference the [[#sharedLibrary|sharedLibrary]] property. As you will see in the code samples, this results in some extra length being added to the lines of code. However, since it is a Singleton, it is shared across your application, so you will never need to create instances of it.
+
-
<b>Configuration Keys</b><br />
+
== Key Concepts ==
-
This SDK uses a concept of configuration keys to access data and instantiate views. Each active promotion that your organization has with ePrize will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations ([[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]]), and to instantiate promo views ([[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]). The array of keys is stored in the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] [[#sharedLibrary|sharedLibrary]] for access anywhere in your application.
+
-
&nbsp;<br />
+
-
=== Step 1: Obtain the EPrizeMobileSDK ===
+
=== Singleton Classes ===
 +
The SDK includes a number of Singleton classes which you will not create instances of, but rather, can simply reference the shared Singleton property for each respective class. The Singleton classes/properties used in the SDK include:
 +
* &#91;[[Mobile_SDK_iOS:_EPZAnalyticsService|EPZAnalyticsService]] [[Mobile_SDK_iOS:_EPZAnalyticsService#sharedService|sharedService]]&#93;
 +
* &#91;[[Mobile_SDK_iOS:_EPZPromoLibrary|EPZPromoLibrary]] [[Mobile_SDK_iOS:_EPZPromoLibrary#sharedLibrary|sharedLibrary]]&#93;
 +
* &#91;[[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]] [[Mobile_SDK_iOS:_EPZPushNotificationService#sharedService|sharedService]]&#93;
-
Please contact your account team or Producer to obtain your copy of the ePrize Mobile SDK.
+
=== Callback Blocks ===
 +
Version 2.0 of this SDK includes a major shift in the callback logic used. Where version 1.0 used delegates as the primary method of implementing callbacks from the SDK, version 2.0 introduces blocks as the main callback method for the majority of public methods in all Singleton classes. As you will see in the class-specific documentation, there are block arguments for all methods which utilize blocks as the callback methods. This said, there are still instances of delegates and delegate methods, namely in the SDK's built-in view controllers.
-
<i>Please note: It is highly recommended that you save the framework to a specific and static location on your computer (e.g. a location where you save other third-party SDKs and frameworks). This can allow you to better use the framework across multiple projects, if needed.</i>
+
=== Configuration Keys ===
 +
The SDK uses a concept of configuration keys to access data about promotions and instantiate certain views. Each active promotion will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations ([[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]]), and to instantiate the SDK's built-in web view controller ([[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]). The array of keys is stored in the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] [[#sharedLibrary|sharedLibrary]] for access anywhere in your application.
-
=== Step 2: Include framework into your project ===
 
-
In your application’s project navigator, click on the Build Phases tab in your project’s target. Under “Link Binary With Libraries”, click the “+” button and select “Add Other” from the dialog box. Navigate to the EPrizeMobileSDK.framework directory you saved from step 1 above, and click “Open”. The EPrizeMobileSDK framework is now included in your project and ready to use.
+
== Getting Started ==
-
=== Step 3: Import framework as necessary ===
+
The SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with HelloWorld, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.
-
In any class file that needs to utilize the SDK, you will need to import the framework files. You can consult the [[#Class_Documentation:_EPZPromoLibrary|EPrizeMobileSDK Class Documentation]] section below for more information about each of the classes included in the SDK.
+
Additionally, the SDK offers the ability to integrate push notifications into your application, including the ability for users to customize the types of notifications they would like to receive.
-
== Sample Integration ==
+
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Please note:</b> Using this SDK requires a valid client key provided by HelloWorld. If you wish to integrate with the SDK’s Push Notification Service, you will also need a valid push key. If you do not have a client key and/or push key, please contact your account team or Producer. </i></div>
-
The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.
+
=== Obtain the EPrizeMobileSDK ===
-
=== Step 1: Set Client Key ===
+
Please contact your account team or Producer to obtain your copy of the SDK.
-
In your AppDelegate.m file, import the EPrizeMobileSDK and set the client key property for the shared library.
+
<i>Please note: It is highly recommended that you save the framework to a specific and static location on your computer (e.g. a location where you save other third-party SDKs and frameworks). This can allow you to better use the framework across multiple projects, if needed.</i>
-
<i>Recommendation: Set this in the</i> application:didFinishLaunchingWithOptions: <i>method. </i>
 
-
<pre>
+
=== Include framework into your project ===
-
#import <EPrizeMobileSDK/EPrizeMobileSDK.h>
+
-
@implementation AppDelegate
+
In your application’s project navigator, click on the Build Phases tab in your project’s target. Under “Link Binary With Libraries”, click the “+” button and select “Add Other” from the dialog box. Navigate to the EPrizeMobileSDK.framework directory you saved from step 1 above, and click “Open”. The EPrizeMobileSDK framework is now included in your project and ready to use.
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 
-
{
 
-
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
 
-
// Set Client Key - Absolutely required to make calls to retrieve configurations
+
=== Import framework as necessary ===
-
[[EPZPromoLibrary sharedLibrary] setClientKey:@"your_client_key"];
+
-
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
+
In any class file that needs to utilize the SDK, you will need to import the framework files. You can consult the various [[#Class_Documentation|Class Documentation]] sections for more information about each of the classes included in the SDK.
-
self.window.rootViewController = self.viewController;
+
-
[self.window makeKeyAndVisible];
+
-
return YES;
+
-
}
+
-
</pre>
+
-
=== Step 2: Conform to Applicable Delegate Protocols ===
 
-
Wherever you choose to integrate the retrieval of configuration data and present a promotion using the SDK’s built-in web view controller, you will need to conform to the [[#Class_Documentation:_EPZPromoLibraryDelegate_Protocol_Reference|EPZPromoLibraryDelegate]] and [[#Class_Reference:_EPZPromoWebViewControllerDelegate_Protocol_Reference|EPZPromoWebViewControllerDelegate]] protocols, respectively.
+
=== Set up and provide necessary files for Push Notifications ===
-
<pre>
+
If you are integrating with the SDK’s Push Notification Service, you will need to follow the appropriate steps to set up your application to use push notifications, both for Development and Production.
-
#import <EPrizeMobileSDK/EPrizeMobileSDK.h>
+
-
@interface ViewController : UIViewController
+
==== Create App ID ====
-
<EPZPromoLibraryDelegate, EPZPromoWebViewControllerDelegate>
+
-
</pre>
+
-
=== Step 3: Set Delegate and Fetch Promotion Configurations ===
+
In the Apple Developer Center, you will need to create an explicit App ID for your application. You will need to make sure that you enable the <b>Push Notifications</b> service under the "App Services" section of the App ID generation process.
-
When you want to fetch promotion configurations, you will need to set the [[#sharedLibrary|sharedLibrary]] [[#delegate|delegate]] and call the [[#fetchPromotionConfigurations|fetchPromotionConfigurations]] method. Additionally, you’ll need to implement the required protocol method [[#promotionConfigurationsRetrieved:|promotionConfigurationsRetrieved:]], and optionally, the [[#promotionConfigurationsFailedWithError:|promotionConfigurationsFailedWithError:]] method.
+
==== Create Certificate & Export Private Key ====
-
<pre>
+
Once you have created your App ID, you will need to create a certificate which you will need to link to the App ID created in the previous step. After you have generated and downloaded the certificate, make sure you double-click the downloaded file to add to Keychain Access. Then, in Keychain Access, find the new private key created, right-click it, and choose the "Export" option. Save the private key as a .p12 file.
-
#import <EPrizeMobileSDK/EPrizeMobileSDK.h>
+
-
@implementation ViewController
+
==== Create Provisioning Profile ====
-
- (void)viewDidLoad
+
You will also need to make sure you set up a valid provisioning profile for your application in the Apple Developer Center, complete with the applicable App ID and certificates.
-
{
+
-
[super viewDidLoad];
+
-
+
-
[[EPZPromoLibrary sharedLibrary] setDelegate:self];
+
-
[[EPZPromoLibrary sharedLibrary] fetchPromotionConfigurations];
+
-
}
+
-
- (void) promotionConfigurationsRetrieved:(NSArray *)promoKeys
+
-
{
+
-
// promoKeys is an array of promotion configuration keys.
+
-
// Use this array as needed to display a promotion, list
+
-
// of promotions, or other call-to-action as needed.
+
-
}
+
-
- (void) promotionConfigurationsFailedWithError:(NSError *)error
+
-
{
+
-
// The error param will contain info about the error so
+
-
// you can handle appropriately.
+
-
}
+
-
</pre>
+
-
=== Step 4: Launching and Closing a Promotion ===
+
==== Create a PEM File ====
-
If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion site in your app. To do so, you need to make an instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]], initializing it with a configuration key. Then set a transition style, set it’s delegate to self, and present it.
+
Once you have your Certificate and private key as a .p12 file, you need to convert them into a more usable format. To do this, launch Terminal, navigate to the directory where both files are saved, and follow the steps below. <i>(Note: The filenames used in the code snippets may differ depending on whether you are using the development or production certificate, depending on what you named your private key .p12 file, and what you would like to name your PEM files.)</i>
-
<i>(Note: In the code snippet below, “config” is an instance of </i>[[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]]<i>, and utilizes the shared library’s </i>[[#promotionConfigurationForKey:|promotionConfigurationForKey:]]<i> method, as well as referencing the sharedLibrary to get one of the keys from the promoKeys property. For more information on these classes and how to use them, see the class reference documentation for each. For more information on the concept of configuration keys, see [[#Key_Concepts|Key Concepts]] section in the Getting Started guide.)</i>
+
:<b>Convert the .cer file into a .pem file</b>
 +
<pre>openssl x509 -in aps_development.cer -inform der -out MyDevCert.pem</pre>
-
<pre>
+
:<b>Convert private key .p12 file into a .pem file</b>
-
EPZPromoConfiguration *config = [[EPZPromoLibrary sharedLibrary] promotionConfigurationForKey:[[[EPZPromoLibrary sharedLibrary] promoKeys] objectAtIndex:0]];
+
<pre>openssl pkcs12 -nocerts -out MyDevKey.pem -in MyDevKey.p12 -nodes</pre>
-
EPZPromoWebViewController *pvc = [[EPZPromoWebViewController alloc] initWithPromoConfigKey:config.configKey options:nil];
+
:<b>Combine certificate and key files into one .pem file</b>
 +
<pre>cat MyDevCert.pem MyDevKey.pem > MyCombinedDevCertAndKey.pem</pre>
-
pvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
 
-
pvc.delegate = self;
+
==== Submit Required Information to HelloWorld ====
 +
Once you have the combined PEM file as specified above, create an archive ZIP file of the PEM file along with a plain text file that includes your App Bundle ID, App Name, and Push Key (see sample below). <b>Submit this ZIP file to your HelloWorld account team or Producer.</b>
-
[self presentViewController:pvc animated:YES completion:nil];
+
:<b>Sample Text File</b>
 +
<pre>
 +
App Bundle ID: com.helloworld.mobilesdk.pushdemo
 +
App Name: MobileSDK Push Demo App
 +
Push Key: push_dev_multi
</pre>
</pre>
-
The [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] includes a required delegate method, [[#closePromoView:|closePromoView:]], which is shown below. It alerts the delegate when the user has clicked on the “Close” button in the web view controller. When this method is called, you should take the necessary steps to hide and remove the instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]].
+
<blockquote style="background:#ffd; border:1px solid #ddc; padding:20px;"><i><b>Important Note:</b>
 +
<br /><br />
 +
If you have requested using a different Push Key for development/testing than you are for your final production release, you will need to use a unique App Bundle ID for each. The app bundle ID value is used as a unique identifier for your app in the Push Notification Service back-end. As such, using the same bundle ID value for development/testing and the final production app will cause issues with sending push notifications to devices that are using your application. In this case, you will need to submit the above information for both versions of your app.</i></blockquote>
-
<pre>
+
== Sample Integration ==
-
- (void) closePromoView:(EPZPromoWebViewController *)controller
+
-
{
+
-
[self dismissViewControllerAnimated:YES completion:nil];
+
-
// Add additional logic here, as necessary.
+
-
}
+
-
</pre>
+
 +
The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.
-
If for any reason you do not or cannot set the delegate for the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]], there is an additional way to listen for the close event. In the absence of the delegate responding to the [[#closePromoView:|closePromoView:]] method, a notification will be sent to the default notification center, to which you can add an observer, like outlined in the example below.
+
=== Set Client and Push Keys ===
-
Note that "EPZ_NOTIFICATION_CLOSE_VIEW" is a constant defined in [[#Class_Documentation:_EPZConstants|EPZConstants]].
+
In your AppDelegate.m file, set the [[Mobile_SDK_iOS:_EPZPromoLibrary#clientKey|clientKey]] property for the [[Mobile_SDK_iOS:_EPZPromoLibrary#sharedLibrary|sharedLibrary]]. If you are integrating with the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]], you will also need to set the [[Mobile_SDK_iOS:_EPZPushNotificationService#pushKey|pushKey]] property for the [[Mobile_SDK_iOS:_EPZPushNotificationService#sharedService|sharedService]], as well as call the registerForRemoteNotificationTypes: method on the shared UIApplication.
 +
 
 +
<i>Recommendation: Set this in the</i> application:didFinishLaunchingWithOptions: <i>method. </i>
<pre>
<pre>
Line 139: Line 121:
{
{
...
...
-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(epzCloseViewNotification:) name:EPZ_NOTIFICATION_CLOSE_VIEW object:nil];
 
-
...
 
-
}
 
-
- (void) epzCloseViewNotification:(NSNotification *)notification
 
-
{
 
-
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
 
-
[navController dismissViewControllerAnimated:YES completion:nil];
 
-
}
 
-
</pre>
 
-
== Class Documentation: EPZPromoLibrary ==
+
// Set Client Key - Absolutely required to integrate with the SDK
 +
[[EPZPromoLibrary sharedLibrary] setClientKey:@"your_client_key"];
-
=== Overview ===
+
// Set Push Key - Required if integrating with the SDK's Push Notification Service
 +
[[EPZPushNotificationService sharedService] setPushKey:@"your_push_key"];
-
The EPZPromoLibrary class is a Singleton class that provides the necessary logic to connect to the ePrize servers. It is the workhorse of the SDK, providing the methods to retrieve and store the full list of promotion configurations.
+
// Register for push notifications, if integrating with the SDK's Push Notification Service
 +
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
 +
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
 +
[[UIApplication sharedApplication] registerForRemoteNotifications];
 +
} else {
 +
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert)];
 +
}
-
Since this class is a Singleton, you will not create an instance of it. Rather, you will simply reference the [[#sharedLibrary|sharedLibrary]] property to access the data (properties) stored within the class, and methods to be called from the class.
+
...
-
 
+
return YES;
-
For example, to set the client key property:
+
}
-
<pre>
+
-
[[EPZPromoLibrary sharedLibrary] setClientKey: @"your_key_here”];
+
</pre>
</pre>
-
...or to fetch promotion configurations:
+
If you have requested different Push Keys for development/testing and the final production release, you will need to set the [[Mobile_SDK_iOS:_EPZPushNotificationService#appID|appID]] value for the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]]. It is advisable in such an instance to set your Push Key and App ID dynamically, as in the code sample below:
-
<pre>
+
-
[[EPZPromoLibrary sharedLibrary] fetchPromotionConfigurations];
+
-
</pre>
+
-
 
+
-
 
+
-
=== Tasks ===
+
-
 
+
-
<b>Getting the Shared Library Instance</b><br />
+
-
[[#sharedLibrary|+ sharedLibrary]]
+
-
 
+
-
<b>Setting and Getting the Delegate</b><br />
+
-
[[#delegate|&nbsp; &nbsp;delegate]] <i>property</i>
+
-
 
+
-
<b>Retrieving Promotion Information</b><br />
+
-
[[#fetchPromotionConfigurations|- fetchPromotionConfigurations]]<br />
+
-
[[#promotionConfigurationForKey:|- promotionConfigurationForKey:]]<br />
+
-
&nbsp; [[#promoConfigurations|promoConfigurations]] <i>property</i><br />
+
-
&nbsp; [[#promoKeys|promoKeys]] <i>property</i>
+
-
 
+
-
<b>Launching a Promotion (in device's native browser)</b><br />
+
-
[[#launchPromotionForKey:|- launchPromotionForKey:]]
+
-
 
+
-
<b>Accessing the Client Key</b><br />
+
-
&nbsp; [[#clientKey|clientKey]] <i>property</i>
+
-
 
+
-
<b>SDK Information</b><br />
+
-
&nbsp; [[#version|version]] <i>property</i>
+
-
 
+
-
 
+
-
=== Properties ===
+
-
==== delegate ====
 
-
The receiver's delegate.
 
<pre>
<pre>
-
@property (nonatomic, assign) id <EPZPromoLibraryDelegate> delegate
+
#ifdef DEBUG
 +
[[EPZPushNotificationService sharedService] setPushKey:@"your_dev_push_key"];
 +
[[EPZPushNotificationService sharedService] setAppID:@"com.helloworld.pushdemo.dev"];
 +
#else
 +
[[EPZPushNotificationService sharedService] setPushKey:@"your_prod_push_key"];
 +
[[EPZPushNotificationService sharedService] setAppID:@"com.helloworld.pushdemo.prod"];
 +
#endif
</pre>
</pre>
-
<b>Discussion</b><br />
+
=== Fetch Promotion Configurations ===
-
The delegate is sent messages when server data actions are fired. See [[#Class_Documentation:_EPZPromoLibraryDelegate_Protocol_Reference|EPZPromoLibraryDelegate Protocol Reference]] for methods this delegate implements.
+
-
<b>Availability</b><br />
+
When you want to fetch promotion configurations, you will need to pass in a block that will be triggered when the [[Mobile_SDK_iOS:_EPZPromoLibrary#fetchPromotionConfigurations:|fetchPromotionConfigurations:]] method is complete. Since the same block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block, like in the code sample below.
-
Available in version 1.0 and later.
+
-
<b>Declared In</b><br />
+
For more information on fetching promotion configurations, consult the [[Mobile_SDK_iOS:_EPZPromoLibrary#fetchPromotionConfigurations:|fetchPromotionConfigurations:]] method documentation.
-
EPZPromoLibrary.h
+
- 
-
==== clientKey ====
 
-
The client key used by your application.
 
<pre>
<pre>
-
@property (nonatomic, copy) NSString *clientKey
+
[[EPZPromoLibrary sharedLibrary] fetchPromotionConfigurations:^(NSArray *data, NSError *error) {
 +
if (error) {
 +
// Handle error as needed.
 +
} else {
 +
// Successfully retrieved promotion configurations.
 +
}
 +
}];
</pre>
</pre>
-
<b>Discussion</b><br />
+
=== Launching and Closing a Promotion ===
-
The client key is used to retrieve the list of promotion configurations from the ePrize servers. This value should be set in your App Delegate (in the application:didFinishLaunchingWithOptions: method, for instance) so it is ready to use anywhere in your code.
+
-
<b>Availability</b><br />
+
If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion site in your app. To do so, you need to create an instance of [[Mobile_SDK_iOS:_EPZPromoWebViewController|EPZPromoWebViewController]] and add it to your application, similar to the following code sample. Note that "config" makes use of the [[Mobile_SDK_iOS:_EPZPromoLibrary#sharedLibrary|sharedLibrary]] to retrieve the [[Mobile_SDK_iOS:_EPZPromoConfiguration|EPZPromoConfiguration]] object, and the configuration's [[Mobile_SDK_iOS:_EPZPromoConfiguration#configKey|configKey]] is in turn used to initialize the [[Mobile_SDK_iOS:_EPZPromoWebViewController|EPZPromoWebViewController]].
-
Available in version 1.0 and later.
+
-
<b>Declared In</b><br />
+
For more information, you can consult the documentation for [[Mobile_SDK_iOS:_EPZPromoWebViewController|EPZPromoWebViewController]] and [[Mobile_SDK_iOS:_EPZPromoWebViewControllerDelegate|EPZPromoWebViewControllerDelegate]]
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== promoConfigurations ====
+
-
A dictionary of promotion configurations. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSDictionary *promoConfigurations
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a quick and full list of [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] objects, each keyed with its configuration’s [[#configKey|configKey]] value. It is a more verbose alternative to the [[#promoKeys|promoKeys]] property, which simply provides a list of configuration keys.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== promoKeys ====
+
-
An array of promotion configuration keys. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSArray *promoKeys
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a quick list of configuration keys available. It is a smaller alternative to the [[#promoConfigurations|promoConfigurations]] property, which provides a more verbose set of data.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== version ====
+
-
The version of the EPrizeMobileSDK. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) float version
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This is a convenience property that returns the version number of the EPrizeMobileSDK framework you are using.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
=== Class Methods ===
+
-
 
+
-
==== sharedLibrary ====
+
-
Returns the singleton library instance.
+
-
<pre>
+
-
+ (EPZPromoLibrary *)sharedLibrary
+
-
</pre>
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
=== Instance Methods ===
+
-
 
+
-
==== promotionConfigurationForKey: ====
+
-
Returns an instance of the [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] object, which contains information relevant to a promotion.
+
-
<pre>
+
-
- (EPZPromoConfiguration *)promotionConfigurationForKey:(NSString *)key
+
-
</pre>
+
-
 
+
-
<b>Parameters</b><br />
+
-
key<br />
+
-
<span style="margin-left: 30px;">One of the configuration keys that is stored in the [[#promoKeys|promoKeys]] property. </span>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This method lets you get an [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] object with the key specified as a parameter. It is an easy convenience method to use to get access to a promotion’s configuration data. For more information on the [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] object, see the documentation for [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]].
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== fetchPromotionConfigurations ====
+
-
Retrieves a list of promotion configurations from the ePrize servers.
+
-
<pre>
+
-
- (void)fetchPromotionConfigurations
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This method makes an asynchronous request to retrieve a list of promotion configuration keys, using the [[#clientKey|clientKey]] property value (which should be set in your App Delegate so it is ready to use when needed). Upon completion of the request, one of the [[#Class_Documentation:_EPZPromoLibraryDelegate_Protocol_Reference|EPZPromoLibraryDelegate]] methods will be called, alerting the delegate of either success or error.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== launchPromotionForKey: ====
+
-
Calls the openURL method on the parent app’s UIApplication sharedApplication instance.
+
-
<pre>
+
-
- (void)launchPromotionForKey:(NSString *)key
+
-
</pre>
+
-
 
+
-
<b>Parameters</b><br />
+
-
key<br />
+
-
<span style="margin-left: 30px;">One of the configuration keys that is stored in the promoKeys property. </span>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This is a convenience method to easily launch a promotion for a given key, using the device’s default web browser.
+
-
 
+
-
<i>Note: It is recommended that you do not use this method, but rather create an instance of</i> [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] <i>and this view to your app so the promotion will be viewed while staying in your app. As a safeguard, this method will not complete if the promotion configuration for the specified key has an</i> [[#openInNativeBrowser|openInNativeBrowser]] <i>value of NO.</i>
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
== Class Documentation: EPZPromoLibraryDelegate Protocol Reference ==
+
-
 
+
-
=== Overview ===
+
-
 
+
-
The EPZPromoLibraryDelegate protocol defines methods that a delegate of [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] can implement to handle actions pertaining to interactions with the class methods.
+
-
 
+
-
 
+
-
=== Tasks ===
+
-
 
+
-
<b>Retrieving Content</b><br />
+
-
[[#promotionConfigurationsRetrieved:|- promotionConfigurationsRetrieved:]] <i>required method</i><br />
+
-
[[#promotionConfigurationsFailedWithError:|- promotionConfigurationsFailedWithError:]] <i>optional method</i>
+
-
 
+
-
 
+
-
=== Instance Methods ===
+
-
 
+
-
==== promotionConfigurationsRetrieved: ====
+
-
Returns a list of promotion configuration keys after successful retrieval.
+
-
<pre>
+
-
- (void) promotionConfigurationsRetrieved:(NSArray *)promoKeys
+
-
</pre>
+
-
 
+
-
<b>Parameters</b><br />
+
-
promoKeys<br />
+
-
<div style="margin-left: 30px;">An array of promotion configuration keys. Promotion configuration keys are used to retrieve [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] objects from the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] [[#sharedLibrary|sharedLibrary]] property, and to instantiate an instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. Like the name indicates, these are “key” values that allow access to the configuration objects and successful view controller instantiation. Without a valid promo key, you will not be able to retrieve specific promotion configuration data or instantiate web view controllers.
+
-
 
+
-
<i>Note: This array may be empty, if no current promotions are found for the specified client key. You will be responsible for incorporating logic to determine array length, and add functionality to your app to handle the various scenarios of array length.</i>
+
-
</div>
+
-
 
+
-
 
+
-
<b>Discussion</b><br />
+
-
The delegate responds to the callback method from a successful NSURLConnection to retrieve configuration data.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
==== promotionConfigurationsFailedWithError: ====
+
-
Called if retrieving a list of promotion configurations was unsuccessful due to an error.
+
-
<pre>
+
-
- (void) promotionConfigurationsFailedWithError:(NSError *)error
+
-
</pre>
+
-
 
+
-
<b>Parameters</b><br />
+
-
error<br />
+
-
<div style="margin-left: 30px;">An NSError object containing information with the reason the call to retrieve promotion configurations was unsuccessful.
+
-
 
+
-
<i>Note: If the error is due to a lack of Internet connectivity, you will need to take appropriate actions to attempt to retrieve promotion configurations again, as the SDK does not automatically attempt to do so.</i>
+
-
</div>
+
-
 
+
-
 
+
-
<b>Discussion</b><br />
+
-
The delegate responds to the callback method from an unsuccessful NSURLConnection to retrieve configuration data.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoLibrary.h
+
-
 
+
-
 
+
-
== Class Documentation: EPZPromoConfiguration ==
+
-
 
+
-
=== Overview ===
+
-
 
+
-
The EPZPromoConfiguration class stores all necessary information specific to a promotion. You can use an instance of this class to gain access to all of the applicable pieces of information you’ll need for reference, display, and functionality. All properties of this class are read-only.
+
-
 
+
-
<i>Note: There are methods named</i> initWithKey:data: <i>and </i>promoConfigurationWithKey:data: <i>which are not meant to be used outside of the core SDK logic, and thus, are not documented below. </i>
+
-
 
+
-
 
+
-
=== Tasks ===
+
-
 
+
-
<b>Getting Promotion Configuration Information</b><br />
+
-
&nbsp; [[#configKey|configKey]] <i>property</i><br />
+
-
&nbsp; [[#configType|configType]] <i>property</i><br />
+
-
&nbsp; [[#displayURL|displayURL]] <i>property</i><br />
+
-
&nbsp; [[#endpointURL|endpointURL]] <i>property</i><br />
+
-
&nbsp; [[#promoTitle|promoTitle]] <i>property</i><br />
+
-
&nbsp; [[#assetURLs|assetURLs]] <i>property</i><br />
+
-
&nbsp; [[#openInNativeBrowser|openInNativeBrowser]] <i>property</i><br />
+
-
&nbsp; [[#endDate|endDate]] <i>property</i><br />
+
-
&nbsp; [[#launchDate|launchDate]] <i>property</i>
+
-
 
+
-
<b>Altering the Endpoint URL</b><br />
+
-
&nbsp; [[#appendEndpointURLWithData:|- appendEndpointURLWithData:]]
+
-
 
+
-
 
+
-
=== Properties ===
+
-
 
+
-
==== configKey ====
+
-
The promotion’s configuration key. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSString *configKey
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s configuration key, which is used in the initialization function of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. This key is also the same key used to store the [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] object in the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] [[#promoConfigurations|promoConfigurations]] object.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== configType ====
+
-
The promotion’s configuration type. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSString *configType
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s configuration type. As of version 1.0, the only value for this property is “mobileSdkV1”. This property serves little value outside of the core SDK logic.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== displayURL ====
+
-
The promotion’s URL, formatted for display. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSString *displayURL
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s URL, targeted for display. For instance, if a promotion uses a vanity URL, the vanity URL can be the value for this property. Similarly, if a promotion URL has query parameters attached to the URL that are not intended for display, this value may crop off the parameters, resulting in a URL that is more pleasing to the eye.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== endpointURL ====
+
-
The promotion’s full URL. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSString *endpointURL
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s full URL. Unlike the displayURL property, this value may include additional URL information such as query parameters, or a URL that is masked by a vanity URL.
+
-
 
+
-
<b>Important Note:</b> This is the value that is loaded into the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]].
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== promoTitle ====
+
-
The promotion’s title. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSString *promoTitle
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s title.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== assetURLs ====
+
-
A list of the promotion’s asset URLs. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSDictionary *assetURLs
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s asset URLs, as configured in the ePrize Configuration Service.
+
-
 
+
-
<i><b>Important Note: </b> There are no set or default key values for this property, as all asset URLs are the responsibility of the party who configures the promotion in the ePrize Configuration Service. As such, if you choose to use asset URLs, it is recommended to do conditional checks for the existence of any dictionary keys you attempt to use, to avoid null values and/or crashes. </i>
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== openInNativeBrowser ====
+
-
A flag alerting whether the site is intended to launch in a device’s native browser. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) BOOL *openInNativeBrowser
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a flag to alert you whether the promotion is intended to launch in a device’s native browser. You can check this value before launching a promotion in your app, and if it is set to YES, you can use the [[#Class_Documentation:_EPZPromoLibrary|EPZPromoLibrary]] method [[#launchPromotionForKey:|launchPromotionForKey:]], which will open the promotion’s URL in the device’s native browser, rather than in the built-in SDK web view.
+
-
 
+
-
<i>Note: In the interest of giving complete control to your application, the SDK does not automatically open a promotion, either in the native browser or by launching an instance of</i> [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]<i>. You are responsible for triggering a promotion to be opened by one of these two means.</i>
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== endDate ====
+
-
The promotion’s end date. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSDate *endDate
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s end date. If you would like to know and/or display the end date for a promotion, you can use this property to get the value, and then use it as necessary.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
==== launchDate ====
+
-
The promotion’s launch date. (read-only)
+
-
<pre>
+
-
@property (nonatomic, readonly) NSDate *launchDate
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This property provides a reference to the promotion’s launch date. If you would like to know and/or display the launch date for a promotion, you can use this property to get the value, and then use it as necessary.
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
 
+
-
=== Instance Methods ===
+
-
 
+
-
==== appendEndpointURLWithData: ====
+
-
<pre>
+
-
- (void) appendEndpointURLWithData:(NSDictionary *)data
+
-
</pre>
+
-
 
+
-
<b>Discussion</b><br />
+
-
This method allows the ability to append a configuration's endpoint URL with additional data (which is added via query parameters).
+
-
 
+
-
<div style="margin: 20px 0px; padding:20px; background:#ffd; border:1px solid #ddc;"><i><b>Please note:</b> This method will alter the stored value for the endpoint URL. As such, calling this method multiple times, especially with the same data set, is not advisable. If you must call this method, it is strongly recommended you include conditional logic in your app that detects the presence of a specific query parameter on the endpoint URL, and only call this method if no such value exists.</i></div>
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoConfiguration.h
+
-
 
+
-
== Class Documentation: EPZPromoWebViewController ==
+
-
 
+
-
=== 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.
+
-
 
+
-
<b>Creating a View</b><br />
+
-
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|sharedLibrary]] for both retrieval of a configuration object, and the configuration key used to retrieve this configuration object.
+
<pre>
<pre>
 +
// Get first promotion configuration object
EPZPromoConfiguration *config = [[EPZPromoLibrary sharedLibrary] promotionConfigurationForKey:[[[EPZPromoLibrary sharedLibrary] promoKeys] objectAtIndex:0]];
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];
EPZPromoWebViewController *pvc = [[EPZPromoWebViewController alloc] initWithPromoConfigKey:config.configKey options:nil];
-
pvc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
+
// Set delegate
-
 
+
pvc.delegate = self;
pvc.delegate = self;
 +
// Present view controller
[self presentViewController:pvc animated:YES completion:nil];
[self presentViewController:pvc animated:YES completion:nil];
</pre>
</pre>
 +
You will need to conform to the [[Mobile_SDK_iOS:_EPZPromoWebViewControllerDelegate|EPZPromoWebViewControllerDelegate]] protocol, in which one method is required to implement, as seen below. This method alerts the delegate when the user has clicked on the “Close” button in the [[Mobile_SDK_iOS:_EPZPromoWebViewController|EPZPromoWebViewController]]. When this method is called, you should take the necessary steps to hide and remove the instance of the view controller.
-
=== Tasks ===
 
- 
-
<b>Setting and Getting the Delegate</b><br />
 
-
&nbsp; [[#delegate_2|delegate]] <i>property</i>
 
- 
-
<b>Initializing</b><br />
 
-
[[#promoWebViewControllerWithPromoConfigKey:options:|+ promoWebViewControllerWithPromoConfigKey:options:]]<br />
 
-
[[#promoWebViewControllerWithURL:options:|+ promoWebViewControllerWithURL:options:]]<br />
 
-
[[#initWithPromoConfigKey:options:|- initWithPromoConfigKey:options:]]<br />
 
-
[[#initWithURL:options:|- initWithURL:options:]]
 
- 
-
=== Properties ===
 
- 
-
==== delegate ====
 
-
The receiver's delegate.
 
<pre>
<pre>
-
@property (nonatomic, assign) id <[[#Class_Reference:_EPZPromoWebViewControllerDelegate_Protocol_Reference|EPZPromoWebViewControllerDelegate]]> delegate
+
- (void) closePromoWebView:(EPZPromoWebViewController *)controller
 +
{
 +
[self dismissViewControllerAnimated:YES completion:nil];
 +
// Add additional logic here, as necessary.
 +
}
</pre>
</pre>
-
<b>Discussion</b><br />
+
=== Subscribing and Unsubscribing a User with the EPZPushNotificationService ===
-
The delegate is sent messages when the view is created, as well as when it is targeted to close. See [[#Class_Reference:_EPZPromoWebViewControllerDelegate_Protocol_Reference|EPZPromoWebViewControllerDelegate Protocol Reference]] for methods this delegate implements.
+
-
<b>Availability</b><br />
+
If you are integrating with the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]], you will also want to handle subscribing the user's device in the application:didRegisterForRemoteNotificationsWithDeviceToken: method, as seen in the following code sample. Note that the [[Mobile_SDK_iOS:_EPZPushNotificationService#subscribeUserWithDeviceToken:callback:|subscribeUserWithDeviceToken:callback:]] method is surrounded by a conditional check, and only called if the device is not already subscribed. While not necessary, it saves the need to call this method every time the application launches.
-
Available in version 1.0 and later.
+
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
=== Class Methods ===
 
- 
-
==== promoWebViewControllerWithPromoConfigKey:options: ====
 
-
Initializes and returns a newly allocated view object with the specified items from the options.
 
<pre>
<pre>
-
+ (EPZPromoWebViewController *) promoWebViewControllerWithPromoConfigKey:(NSString *)key options:(NSDictionary *)options
+
// AppDelegate.m
 +
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
 +
{
 +
if (![EPZPushNotificationService sharedService].userIsSubscribed) {
 +
[[EPZPushNotificationService sharedService] subscribeUserWithDeviceToken:deviceToken callback:^(NSError *error) {
 +
if (error) {
 +
// Error subscribing user. Handle error as needed.
 +
} else {
 +
// User successfully subscribed. Safe to call the fetchPushNotificationPreferences: method
 +
}
 +
}];
 +
}
 +
}
</pre>
</pre>
-
<b>Parameters</b><br />
+
It is advisable to allow a user to unsubscribe from push notifications and the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]]. As such, you may need to call the [[Mobile_SDK_iOS:_EPZPushNotificationService#unsubscribeUser:|unsubscribeUser:]] method, as seen in the example below.
-
key<br />
+
-
<div style="margin-left: 30px;">The promotion configuration key for the target promotion you wish to show in the view. Promotion configuration keys are stored in the [[#sharedLibrary|sharedLibrary]] [[#promoKeys|promoKeys]] array, and are properties of all instances of [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] included in the [[#sharedLibrary|sharedLibrary]] [[#promoConfigurations|promoConfigurations]] object.
+
-
<i>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.</i>
+
Note that, like the subscribe example above, the [[Mobile_SDK_iOS:_EPZPushNotificationService#unsubscribeUser:|unsubscribeUser:]] method is surrounded by a conditional check, and only called if the user is subscribed.
-
</div>
+
-
options<br />
 
-
<div style="margin-left: 30px;">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:|initWithPromoConfigKey:options:]] method.</div>
 
- 
- 
-
<b>Discussion</b><br />
 
-
This method returns an initialized instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. Once initialized, this view loads the [[#endpointURL|endpointURL]] value for the specified promotion configuration key into an instance of UIWebView. 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.
 
- 
-
<i>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).</i>
 
- 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>See Also</b><br />
 
-
[[#initWithPromoConfigKey:options:|initWithPromoConfigKey:options:]]
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
==== promoWebViewControllerWithURL:options: ====
 
-
Returns a newly allocated and initizlized view object with the specified items from the options.
 
<pre>
<pre>
-
+ (EPZPromoWebViewController *) promoWebViewControllerWithURL:(NSString *)url options:(NSDictionary *)options
+
if ([EPZPushNotificationService sharedService].userIsSubscribed) {
 +
[[EPZPushNotificationService sharedService] unsubscribeUser:^(NSError *error) {
 +
if (error) {
 +
// Error unsubscribing user. Handle error as needed.
 +
} else {
 +
// User successfully unsubscribed.
 +
}
 +
}];
 +
}
</pre>
</pre>
-
<b>Parameters</b><br />
+
=== Fetch & Set Push Notification Preferences ===
-
url<br />
+
If you are integrating with the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]], you will likely want to fetch a user's push notification preferences, and provide them with the ability to fine-tune which types of notifications they receive.
-
<div style="margin-left: 30px;">The URL for the web page you wish to show in the view. </div>
+
-
options<br />
+
To fetch a user's push preferences, you will call the [[Mobile_SDK_iOS:_EPZPushNotificationService#fetchPushNotificationPreferences:|fetchPushNotificationPreferences:]] method, as in the example below. Note that since the block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block.
-
<div style="margin-left: 30px;">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:|initWithPromoConfigKey:options:]] method.</div>
+
- 
-
<b>Discussion</b><br />
 
-
This is a convenience method that returns an initialized instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. Once initialized, this view loads the URL into an instance of UIWebView. 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.
 
- 
-
<i>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).</i>
 
- 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>See Also</b><br />
 
-
[[#initWithURL:options:|initWithURL:options:]]
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
=== Instance Methods ===
 
- 
-
==== initWithPromoConfigKey:options: ====
 
-
Initializes and returns a newly allocated view object with the specified items from the options.
 
<pre>
<pre>
-
- (id) initWithPromoConfigKey:(NSString *)key options:(NSDictionary *)options
+
[[EPZPushNotificationService sharedService] fetchPushNotificationPreferences:^(NSDictionary *data, NSError *error) {
 +
if (error) {
 +
// Handle error as needed.
 +
} else {
 +
// Successfully retrieved push notification preferences.
 +
}
 +
}];
</pre>
</pre>
-
<b>Parameters</b><br />
+
Once a user's push notification preferences have been retrieved, you can make use of the SDK's built-in [[Mobile_SDK_iOS:_EPZPushPreferencesViewController|EPZPushPreferencesViewController]] to display the user's preferences, and allow them to toggle individual notifications on and off as desired.
-
key<br />
+
-
<div style="margin-left: 30px;">The promotion configuration key for the target promotion you wish to show in the view. Promotion configuration keys are stored in the [[#sharedLibrary|sharedLibrary]] [[#promoKeys|promoKeys]] array, and are properties of all instances of [[#Class_Documentation:_EPZPromoConfiguration|EPZPromoConfiguration]] included in the [[#sharedLibrary|sharedLibrary]] [[#promoConfigurations|promoConfigurations]] object.
+
-
<i>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.</i>
+
To use the SDK's built-in view controller, you will implement logic similar to creating and displaying an instance of the [[Mobile_SDK_iOS:_EPZPromoWebViewController|EPZPromoWebViewController]], as documented above.
-
</div>
+
-
options<br />
+
For more information, you can consult the [[Mobile_SDK_iOS:_EPZPushPreferencesViewController|EPZPushPreferencesViewController]] and [[Mobile_SDK_iOS:_EPZPushPreferencesViewControllerDelegate|EPZPushPreferencesViewControllerDelegate]] documentation pages.
-
<div style="margin-left: 30px;">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.
+
-
<b>toolBar (UIToolbar)</b><br />
 
-
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.
 
-
<div style="padding-left: 30px;"><i>Default: UIToolbar with barStyle of UIBarStyleBlack</i></div>
 
- 
-
<b>closeButton (UIBarButtonItem)</b><br />
 
-
The close button used to close the view.
 
-
<div style="padding-left: 30px;"><i>Default: A UIBarButtonItemStyleBordered with label “Close”</i></div>
 
- 
-
<b>refreshButton (UIBarButtonItem)</b><br />
 
-
The refresh button used to refresh the web page loaded in the view's web view.
 
-
<div style="padding-left: 30px;"><i>Default: UIBarButtonSystemItemRefresh</i></div>
 
- 
-
<b>backButton (UIBarButtonItem)</b><br />
 
-
The back button used navigate back to the previous page in the view's web view.
 
-
<div style="padding-left: 30px;"><i>Default: An inverted instance of UIBarButtonSystemItemPlay</i></div>
 
- 
-
<b>forwardButton (UIBarButtonItem)</b><br />
 
-
The forward button used navigate back to the previous page in the view's web view.
 
-
<div style="padding-left: 30px;"><i>Default: UIBarButtonSystemItemPlay</i></div>
 
- 
-
<b>tintColor (UIColor)</b><br />
 
-
A tint color to apply to the toolbar.
 
-
<div style="padding-left: 30px;"><i>Default: None (no tint color applied)</i></div>
 
- 
-
</div>
 
- 
- 
-
<b>Discussion</b><br />
 
-
This method initializes and returns an instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. Once initialized, this view loads the [[#endpointURL|endpointURL]] value for the specified promotion configuration key into an instance of UIWebView. 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.
 
- 
-
<i>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).</i>
 
- 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>See Also</b><br />
 
-
[[#promoWebViewControllerWithPromoConfigKey:options:|promoWebViewControllerWithPromoConfigKey:options:]]
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
==== initWithURL:options: ====
 
-
Initializes and returns a newly allocated view object with the specified items from the options.
 
<pre>
<pre>
-
- (id) initWithURL:(NSString *)url options:(NSDictionary *)options
+
// Create instance of the view controller
-
</pre>
+
EPZPushPreferencesViewController *pvc = [EPZPushPreferencesViewController pushPreferencesViewControllerWithOptions:nil];
-
<b>Parameters</b><br />
+
// Set delegate
-
url<br />
+
pvc.delegate = self;
-
<div style="margin-left: 30px;">The URL for the web page you wish to show in the view. </div>
+
-
options<br />
+
// Present view controller
-
<div style="margin-left: 30px;">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:|initWithPromoConfigKey:options:]] method.</div>
+
[self presentViewController:pvc animated:YES completion:nil];
-
 
+
-
 
+
-
<b>Discussion</b><br />
+
-
This method initializes and returns an instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]]. Once initialized, this view loads the URL into an instance of UIWebView. 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.
+
-
 
+
-
<i>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).</i>
+
-
 
+
-
 
+
-
<b>Availability</b><br />
+
-
Available in version 1.0 and later.
+
-
 
+
-
<b>See Also</b><br />
+
-
[[#promoWebViewControllerWithURL:options:|promoWebViewControllerWithURL:options:]]
+
-
 
+
-
<b>Declared In</b><br />
+
-
EPZPromoWebViewController.h
+
-
 
+
-
== Class Reference: EPZPromoWebViewControllerDelegate Protocol Reference ==
+
-
 
+
-
=== Overview ===
+
-
 
+
-
The EPZPromoWebViewControllerDelegate protocol defines methods that a delegate of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] can implement to handle actions pertaining to interactions with the class methods.
+
-
 
+
-
 
+
-
=== Tasks ===
+
-
 
+
-
<b>Retrieving Content</b><br />
+
-
[[#closePromoView:|- closePromoView:]] <i>required method</i><br />
+
-
[[#promoViewCreated:|- promoViewCreated:]] <i>optional method</i><br />
+
-
[[#promoView:didFireEvent:withData:|- promoView:didFireEvent:withData:]] <i>optional method</i>
+
-
 
+
-
 
+
-
=== Instance Methods ===
+
-
 
+
-
==== closePromoView: ====
+
-
Dispatched when the view’s “Close” button is pressed.
+
-
<pre>
+
-
- (void) closePromoView:(EPZPromoWebViewController *)controller
+
</pre>
</pre>
-
<b>Parameters</b><br />
+
=== Save Push Preferences ===
-
controller<br />
+
If a user chooses to update their push notification preferences, you'll want to save them on behalf of the user. To do this, you can make use of the [[Mobile_SDK_iOS:_EPZPushNotificationService#savePushNotificationPreferences:|savePushNotificationPreferences:]] method, as seen in the example below.
-
<div style="margin-left: 30px;">The instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] that dispatched the method.</div>
+
-
<b>Discussion</b><br />
+
For more information, you can consult the [[Mobile_SDK_iOS:_EPZPushNotificationService#savePushNotificationPreferences:|savePushNotificationPreferences:]] documentation.
-
The delegate responds to a user clicking on the view’s “Close” button, alerting the delegate to take actions to remove the view from the hierarchy.
+
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
==== promoViewCreated: ====
 
-
Called when the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] view is fully created.
 
<pre>
<pre>
-
- (void) promoViewCreated:(EPZPromoWebViewController *)controller
+
[[EPZPushNotificationService sharedService] savePushNotificationPreferences:^(NSError *error) {
 +
if (error) {
 +
// Handle error as needed.
 +
} else {
 +
// Successfully saved push notification preferences.
 +
}
 +
}];
</pre>
</pre>
-
<b>Parameters</b><br />
+
=== Handle Push Notification & Retrieve Notification Data ===
-
controller<br />
+
If you are integrating with the [[Mobile_SDK_iOS:_EPZPushNotificationService|EPZPushNotificationService]], you will want to implement logic in the application:didReceiveRemoteNotification: method to handle the notification.
-
<div style="margin-left: 30px;">The instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] that dispatched the method.</div>
+
-
<b>Discussion</b><br />
+
For the initial notification payload, a very light set of data is included, which includes a unique remote payload ID value that is needed to retrieve the full set of notification data from the HelloWorld Push Notification Service. The code sample below shows an example of a simple implementation of handling and retrieving full notification data via the [[Mobile_SDK_iOS:_EPZPushNotificationService#fetchAdditionalNotificationDataForPayloadID:callback:|fetchAdditionalNotificationDataForPayloadID:callback:]] method. Like other methods, since the block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block.
-
The delegate responds to the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] view being successfully and fully created. This method is a convenience method you can use if you desire to know when the view was created, to handle other actions in other parts of your application.
+
-
<b>Availability</b><br />
+
For more information on fetching and handling additional notification data, you can consult the documentation for the [[Mobile_SDK_iOS:_EPZPushNotificationService#fetchAdditionalNotificationDataForPayloadID:callback:|fetchAdditionalNotificationDataForPayloadID:callback:]] method.
-
Available in version 1.0 and later.
+
-
<b>Declared In</b><br />
+
Additionally, you can consult the documentation on the [[Mobile_SDK_iOS:_EPZPushNotificationService#recordActionForPushNotificationID:withValue:forAction:callback:|recordActionForPushNotificationID:withValue:forAction:callback:]] method, which offers the ability to record action(s) taken on a specific notification for reporting purposes.
-
EPZPromoWebViewController.h
+
- 
-
==== promoView:didFireEvent:withData: ====
 
-
Called when the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] receives an event from the web page loaded into its web view.
 
<pre>
<pre>
-
- (void) promoView:(EPZPromoWebViewController *)controller didFireEvent:(NSString *)eventName withData:(NSDictionary *)data
+
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
 +
{
 +
// Check notification userInfo for remote payload ID and fetch additional notification data, if found.
 +
NSString *remotePayloadID = [[userInfo objectForKey:EPZ] objectForKey:EPZ_PUSH_KEY_PAYLOAD_ID];
 +
if (remotePayloadID) {
 +
[[EPZPushNotificationService sharedService] fetchAdditionalNotificationDataForPayloadID:remotePayloadId callback:^(NSDictionary *data, NSError *error) {
 +
if (error) {
 +
// Handle error as needed.
 +
} else {
 +
// Additional notification data successfully retrieved. Handle data as needed.
 +
}
 +
}];
 +
}
 +
}
</pre>
</pre>
-
<b>Parameters</b><br />
 
-
controller<br />
 
-
<div style="margin-left: 30px;">The instance of [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] that dispatched the method.</div>
 
-
eventName<br />
 
-
<div style="margin-left: 30px;">The event name triggered. Presently there are no set values for this parameter.</div>
 
-
data<br />
 
-
<div style="margin-left: 30px;">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.</div>
 
- 
-
<b>Discussion</b><br />
 
-
The delegate responds to an event being triggered from the SDK's web view, which catches it from a web page it contains. Presently there is no standard set of events, nor are there standard event data key/value pairs. 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.).
 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoWebViewController.h
 
- 
- 
-
== Class Documentation: EPZAnalyticsService ==
 
- 
-
=== Overview ===
 
- 
-
The EPZAnalyticsService class is a Singleton class that provides the necessary logic to queue events to be tracked inside of an app.
 
- 
-
Since this class is a Singleton, you will not create an instance of it. Rather, you will simply reference the [[#sharedService|sharedService]] property to access the methods to be called from the class.
 
- 
- 
-
=== Tasks ===
 
- 
-
<b>Getting the Shared Service Instance</b><br />
 
-
[[#sharedService|+ sharedService]]
 
- 
-
<b>Queuing Events</b><br />
 
-
[[#queueEvent:data:|- queueEvent:data:]]
 
- 
- 
-
=== Class Methods ===
 
- 
-
==== sharedService ====
 
-
Returns the singleton library instance.
 
-
<pre>
 
-
+ (EPZAnalyticsService *)sharedService
 
-
</pre>
 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>Declared In</b><br />
 
-
EPZAnalyticsService.h
 
- 
- 
-
=== Instance Methods ===
 
- 
-
==== queueEvent:data: ====
 
-
Adds the passed-in event/data into the queue of events to be tracked for the app.
 
-
<pre>
 
-
- (void) queueEvent:(NSString *)event data:(NSDictionary *)data
 
-
</pre>
 
- 
-
<b>Parameters</b><br />
 
-
event<br />
 
-
<span style="margin-left: 30px;">The event name used to track the event. </span>
 
- 
-
data<br />
 
-
<span style="margin-left: 30px;">A dictionary of additional data to pass along with the event. </span>
 
- 
-
<b>Discussion</b><br />
 
-
This method lets you add custom events into the analytics queue used by the SDK. This allows greater flexibility to track user engagement within your app.
 
- 
-
<b>Availability</b><br />
 
-
Available in version 1.0 and later.
 
- 
-
<b>Declared In</b><br />
 
-
EPZPromoLibrary.h
 
- 
- 
-
== Class Documentation: EPZConstants ==
 
- 
-
=== Overview ===
 
- 
-
The EPZConstants class is a simple storage class for constants defined for use in the SDK. The following constants are included:
 
-
<ul>
+
== Class Documentation ==
-
<li><b>EPZ_MOBILE_SDK_VERSION:</b> The version of the SDK <i>(float)</i></li>
+
The SDK includes a number of available classes, whose specific documentation pages can be accessed by clicking one of the links below.
-
<li><b>EPZ_NOTIFICATION_CLOSE_VIEW:</b> Value used for the notification dispatched from the [[#Class_Documentation:_EPZPromoWebViewController|EPZPromoWebViewController]] <i>(NSString)</i></li>
+
:* [[Mobile_SDK_iOS: EPZAnalyticsService|EPZAnalyticsService]]
-
<li><b>EPZ_PROMO_LIBRARY_CLIENT_KEY_SET:</b> Value used inside of the SDK logic to notify when the client key has been set. This value is of no use outside of the internal SDK logic. <i>(NSString)</i></li>
+
:* [[Mobile_SDK_iOS: EPZConstants|EPZConstants]]
-
</ul>
+
:* [[Mobile_SDK_iOS: EPZPromoConfiguration|EPZPromoConfiguration]]
 +
:* [[Mobile_SDK_iOS: EPZPromoLibrary|EPZPromoLibrary]]
 +
:* [[Mobile_SDK_iOS: EPZPromoWebViewController|EPZPromoWebViewController]]
 +
:* [[Mobile_SDK_iOS: EPZPromoWebViewControllerDelegate|EPZPromoWebViewControllerDelegate]]
 +
:* [[Mobile_SDK_iOS: EPZPushNotificationService|EPZPushNotificationService]]
 +
:* [[Mobile_SDK_iOS: EPZPushPreferenceItem|EPZPushPreferenceItem]]
 +
:* [[Mobile_SDK_iOS: EPZPushPreferencesViewController|EPZPushPreferencesViewController]]
 +
:* [[Mobile_SDK_iOS: EPZPushPreferencesViewControllerDelegate|EPZPushPreferencesViewControllerDelegate]]
 +
:* [[Mobile_SDK_iOS: EPZString|EPZString]]
 +
:* [[Mobile_SDK_iOS: EPZWebView|EPZWebView]]
 +
:* [[Mobile_SDK_iOS: EPZWebViewDelegate|EPZWebViewDelegate]]

Revision as of 21:06, 6 November 2014

Contents

OS Support

The HelloWorld Mobile SDK is built for iOS apps targeting iOS 6 and higher.


Version & Release Notes

SDK Version: 2.0

Release Notes:

  • Integration with push notifications
    • Subscribe and unsubscribe from push notifications
    • Fetch, set, and save push notification preferences for specific users (including built-in Push Preferences view controller)
    • Record actions for specific push notifications
  • Analytics tracking events
    • Queue analytics events to be tracked with the SDK’s Analytics Service, complete with custom data, if desired
  • Web View Event Handling
    • Improved integration with web pages loaded into the built-in web view controller, using the HelloWorld MobileSDK JavaScript bridge, allowing correctly-configured events fired off from a web page to bubble up through the SDK and dispatched to the parent app.
  • Improved event dispatching
    • Delegate (and methods) in Singleton classes replaced with block callbacks
Note on naming: You will notice that the SDK uses the historical company name “ePrize” in the framework name, and “EPZ” for the class namespace. Future releases of the SDK may include updates to these names and namespaces to reflect the new company name, HelloWorld, which was introduced in 2014.

Key Concepts

Singleton Classes

The SDK includes a number of Singleton classes which you will not create instances of, but rather, can simply reference the shared Singleton property for each respective class. The Singleton classes/properties used in the SDK include:

Callback Blocks

Version 2.0 of this SDK includes a major shift in the callback logic used. Where version 1.0 used delegates as the primary method of implementing callbacks from the SDK, version 2.0 introduces blocks as the main callback method for the majority of public methods in all Singleton classes. As you will see in the class-specific documentation, there are block arguments for all methods which utilize blocks as the callback methods. This said, there are still instances of delegates and delegate methods, namely in the SDK's built-in view controllers.

Configuration Keys

The SDK uses a concept of configuration keys to access data about promotions and instantiate certain views. Each active promotion will have an associated configuration key. When the list of active promotions is retrieved, you will have access to an array of these configuration keys. You will use the keys to get access to specific promotion configurations (EPZPromoConfiguration), and to instantiate the SDK's built-in web view controller (EPZPromoWebViewController). The array of keys is stored in the EPZPromoLibrary sharedLibrary for access anywhere in your application.


Getting Started

The SDK is designed to be an easy and practical way to retrieve a list of active promotions your organization is running with HelloWorld, Inc. Once you retrieve a list of active promotions, you can use the SDK to launch a given promotion using an instance of the SDK's built-in web view controller, where the specified promotion will be loaded into a customizable web view and presented to the user - all while remaining in your mobile application.

Additionally, the SDK offers the ability to integrate push notifications into your application, including the ability for users to customize the types of notifications they would like to receive.

Please note: Using this SDK requires a valid client key provided by HelloWorld. If you wish to integrate with the SDK’s Push Notification Service, you will also need a valid push key. If you do not have a client key and/or push key, please contact your account team or Producer.

Obtain the EPrizeMobileSDK

Please contact your account team or Producer to obtain your copy of the SDK.

Please note: It is highly recommended that you save the framework to a specific and static location on your computer (e.g. a location where you save other third-party SDKs and frameworks). This can allow you to better use the framework across multiple projects, if needed.


Include framework into your project

In your application’s project navigator, click on the Build Phases tab in your project’s target. Under “Link Binary With Libraries”, click the “+” button and select “Add Other” from the dialog box. Navigate to the EPrizeMobileSDK.framework directory you saved from step 1 above, and click “Open”. The EPrizeMobileSDK framework is now included in your project and ready to use.


Import framework as necessary

In any class file that needs to utilize the SDK, you will need to import the framework files. You can consult the various Class Documentation sections for more information about each of the classes included in the SDK.


Set up and provide necessary files for Push Notifications

If you are integrating with the SDK’s Push Notification Service, you will need to follow the appropriate steps to set up your application to use push notifications, both for Development and Production.

Create App ID

In the Apple Developer Center, you will need to create an explicit App ID for your application. You will need to make sure that you enable the Push Notifications service under the "App Services" section of the App ID generation process.

Create Certificate & Export Private Key

Once you have created your App ID, you will need to create a certificate which you will need to link to the App ID created in the previous step. After you have generated and downloaded the certificate, make sure you double-click the downloaded file to add to Keychain Access. Then, in Keychain Access, find the new private key created, right-click it, and choose the "Export" option. Save the private key as a .p12 file.

Create Provisioning Profile

You will also need to make sure you set up a valid provisioning profile for your application in the Apple Developer Center, complete with the applicable App ID and certificates.

Create a PEM File

Once you have your Certificate and private key as a .p12 file, you need to convert them into a more usable format. To do this, launch Terminal, navigate to the directory where both files are saved, and follow the steps below. (Note: The filenames used in the code snippets may differ depending on whether you are using the development or production certificate, depending on what you named your private key .p12 file, and what you would like to name your PEM files.)

Convert the .cer file into a .pem file
openssl x509 -in aps_development.cer -inform der -out MyDevCert.pem
Convert private key .p12 file into a .pem file
openssl pkcs12 -nocerts -out MyDevKey.pem -in MyDevKey.p12 -nodes
Combine certificate and key files into one .pem file
cat MyDevCert.pem MyDevKey.pem > MyCombinedDevCertAndKey.pem


Submit Required Information to HelloWorld

Once you have the combined PEM file as specified above, create an archive ZIP file of the PEM file along with a plain text file that includes your App Bundle ID, App Name, and Push Key (see sample below). Submit this ZIP file to your HelloWorld account team or Producer.

Sample Text File
App Bundle ID: com.helloworld.mobilesdk.pushdemo
App Name: MobileSDK Push Demo App
Push Key: push_dev_multi
Important Note:

If you have requested using a different Push Key for development/testing than you are for your final production release, you will need to use a unique App Bundle ID for each. The app bundle ID value is used as a unique identifier for your app in the Push Notification Service back-end. As such, using the same bundle ID value for development/testing and the final production app will cause issues with sending push notifications to devices that are using your application. In this case, you will need to submit the above information for both versions of your app.

Sample Integration

The following section outlines steps to get up and running with the EPrizeMobileSDK in your app. These steps provide small code snippets that you can use as reference in your own project. If you need more information about any of the classes, properties, and/or methods used in any of these snippets, please consult the applicable class documentation provided.

Set Client and Push Keys

In your AppDelegate.m file, set the clientKey property for the sharedLibrary. If you are integrating with the EPZPushNotificationService, you will also need to set the pushKey property for the sharedService, as well as call the registerForRemoteNotificationTypes: method on the shared UIApplication.

Recommendation: Set this in the application:didFinishLaunchingWithOptions: method.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...

    // Set Client Key - Absolutely required to integrate with the SDK
    [[EPZPromoLibrary sharedLibrary] setClientKey:@"your_client_key"];

    // Set Push Key - Required if integrating with the SDK's Push Notification Service
    [[EPZPushNotificationService sharedService] setPushKey:@"your_push_key"];

    // Register for push notifications, if integrating with the SDK's Push Notification Service
    if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication	sharedApplication] registerForRemoteNotifications];
    } else {
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert)];
    }

    ...
    return YES;
}

If you have requested different Push Keys for development/testing and the final production release, you will need to set the appID value for the EPZPushNotificationService. It is advisable in such an instance to set your Push Key and App ID dynamically, as in the code sample below:

#ifdef DEBUG
    [[EPZPushNotificationService sharedService] setPushKey:@"your_dev_push_key"];
    [[EPZPushNotificationService sharedService] setAppID:@"com.helloworld.pushdemo.dev"];
#else
    [[EPZPushNotificationService sharedService] setPushKey:@"your_prod_push_key"];
    [[EPZPushNotificationService sharedService] setAppID:@"com.helloworld.pushdemo.prod"];
#endif

Fetch Promotion Configurations

When you want to fetch promotion configurations, you will need to pass in a block that will be triggered when the fetchPromotionConfigurations: method is complete. Since the same block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block, like in the code sample below.

For more information on fetching promotion configurations, consult the fetchPromotionConfigurations: method documentation.

[[EPZPromoLibrary sharedLibrary] fetchPromotionConfigurations:^(NSArray *data, NSError *error) {
    if (error) {
        // Handle error as needed.
    } else {
        // Successfully retrieved promotion configurations.
    }
}];

Launching and Closing a Promotion

If you have at least one active promotion configuration to which you give an accompanying call-to-action, you’ll need a way to display the promotion site in your app. To do so, you need to create an instance of EPZPromoWebViewController and add it to your application, similar to the following code sample. Note that "config" makes use of the sharedLibrary to retrieve the EPZPromoConfiguration object, and the configuration's configKey is in turn used to initialize the EPZPromoWebViewController.

For more information, you can consult the documentation for EPZPromoWebViewController and EPZPromoWebViewControllerDelegate

// 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];

You will need to conform to the EPZPromoWebViewControllerDelegate protocol, in which one method is required to implement, as seen below. This method alerts the delegate when the user has clicked on the “Close” button in the EPZPromoWebViewController. When this method is called, you should take the necessary steps to hide and remove the instance of the view controller.

- (void) closePromoWebView:(EPZPromoWebViewController *)controller
{
    [self dismissViewControllerAnimated:YES completion:nil];
    // Add additional logic here, as necessary.
}

Subscribing and Unsubscribing a User with the EPZPushNotificationService

If you are integrating with the EPZPushNotificationService, you will also want to handle subscribing the user's device in the application:didRegisterForRemoteNotificationsWithDeviceToken: method, as seen in the following code sample. Note that the subscribeUserWithDeviceToken:callback: method is surrounded by a conditional check, and only called if the device is not already subscribed. While not necessary, it saves the need to call this method every time the application launches.

// AppDelegate.m
- (void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    if (![EPZPushNotificationService sharedService].userIsSubscribed) {
        [[EPZPushNotificationService sharedService] subscribeUserWithDeviceToken:deviceToken callback:^(NSError *error) {
            if (error) {
                // Error subscribing user. Handle error as needed.
            } else {
                // User successfully subscribed. Safe to call the fetchPushNotificationPreferences: method
            }
        }];
    }
}

It is advisable to allow a user to unsubscribe from push notifications and the EPZPushNotificationService. As such, you may need to call the unsubscribeUser: method, as seen in the example below.

Note that, like the subscribe example above, the unsubscribeUser: method is surrounded by a conditional check, and only called if the user is subscribed.

if ([EPZPushNotificationService sharedService].userIsSubscribed) {
    [[EPZPushNotificationService sharedService] unsubscribeUser:^(NSError *error) {
        if (error) {
            // Error unsubscribing user. Handle error as needed.
        } else {
            // User successfully unsubscribed.
        }
    }];
}

Fetch & Set Push Notification Preferences

If you are integrating with the EPZPushNotificationService, you will likely want to fetch a user's push notification preferences, and provide them with the ability to fine-tune which types of notifications they receive.

To fetch a user's push preferences, you will call the fetchPushNotificationPreferences: method, as in the example below. Note that since the block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block.

[[EPZPushNotificationService sharedService] fetchPushNotificationPreferences:^(NSDictionary *data, NSError *error) {
    if (error) {
        // Handle error as needed.
    } else {
        // Successfully retrieved push notification preferences.
    }
}];

Once a user's push notification preferences have been retrieved, you can make use of the SDK's built-in EPZPushPreferencesViewController to display the user's preferences, and allow them to toggle individual notifications on and off as desired.

To use the SDK's built-in view controller, you will implement logic similar to creating and displaying an instance of the EPZPromoWebViewController, as documented above.

For more information, you can consult the EPZPushPreferencesViewController and EPZPushPreferencesViewControllerDelegate documentation pages.

// Create instance of the view controller
EPZPushPreferencesViewController *pvc = [EPZPushPreferencesViewController pushPreferencesViewControllerWithOptions:nil];

// Set delegate
pvc.delegate = self;

// Present view controller
[self presentViewController:pvc animated:YES completion:nil];

Save Push Preferences

If a user chooses to update their push notification preferences, you'll want to save them on behalf of the user. To do this, you can make use of the savePushNotificationPreferences: method, as seen in the example below.

For more information, you can consult the savePushNotificationPreferences: documentation.

[[EPZPushNotificationService sharedService] savePushNotificationPreferences:^(NSError *error) {
    if (error) {
        // Handle error as needed.
    } else {
        // Successfully saved push notification preferences.
    }
}];

Handle Push Notification & Retrieve Notification Data

If you are integrating with the EPZPushNotificationService, you will want to implement logic in the application:didReceiveRemoteNotification: method to handle the notification.

For the initial notification payload, a very light set of data is included, which includes a unique remote payload ID value that is needed to retrieve the full set of notification data from the HelloWorld Push Notification Service. The code sample below shows an example of a simple implementation of handling and retrieving full notification data via the fetchAdditionalNotificationDataForPayloadID:callback: method. Like other methods, since the block callback is used for both success and error events, it is advisable to implement a conditional check for the error object in your callback block.

For more information on fetching and handling additional notification data, you can consult the documentation for the fetchAdditionalNotificationDataForPayloadID:callback: method.

Additionally, you can consult the documentation on the recordActionForPushNotificationID:withValue:forAction:callback: method, which offers the ability to record action(s) taken on a specific notification for reporting purposes.

- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    // Check notification userInfo for remote payload ID and fetch additional notification data, if found.
    NSString *remotePayloadID = [[userInfo objectForKey:EPZ] objectForKey:EPZ_PUSH_KEY_PAYLOAD_ID];
    if (remotePayloadID) {
        [[EPZPushNotificationService sharedService] fetchAdditionalNotificationDataForPayloadID:remotePayloadId callback:^(NSDictionary *data, NSError *error) {
            if (error) {
                // Handle error as needed.
            } else {
                // Additional notification data successfully retrieved. Handle data as needed.
            }
        }];
    }
}


Class Documentation

The SDK includes a number of available classes, whose specific documentation pages can be accessed by clicking one of the links below.

Personal tools