Mobile SDK iOS: EPZPromoLibrary

From ePrize Developers Wiki

Revision as of 15:26, 7 November 2014 by Anthony-hessler (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

Overview

The EPZPromoLibrary class is a Singleton class that provides the necessary logic to connect to the HelloWorld servers. It is the workhorse of the SDK, providing the methods to retrieve and store the full list of promotion configurations.

Since this class is a Singleton, you will not create an instance of it. Rather, you will simply reference the sharedLibrary property to access the data (properties) stored within the class, and methods to be called from the class.

For example, to set the client key property:

[[EPZPromoLibrary sharedLibrary] setClientKey:@"your_key_here"];

...or to fetch promotion configurations:

[[EPZPromoLibrary sharedLibrary] fetchPromotionConfigurations:^(NSArray *data, NSError *error) {
    // Handle response here...
}];

Tasks

Getting the Shared Library Instance
+ sharedLibrary

Retrieving Promotion Information
- fetchPromotionConfigurations:
- promotionConfigurationForKey:
  promoConfigurations property
  promoKeys property

Launching a Promotion (in device's native browser)
- launchPromotionForKey:

Accessing the Client Key
  clientKey property

SDK Information
  version property

Debug Flag
  debug property


Properties

clientKey

The client key used by your application.

@property (nonatomic, copy) NSString *clientKey

Discussion
The client key is used to retrieve the list of promotion configurations from the HelloWorld 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.

Declared In
EPZPromoLibrary.h



promoConfigurations

A dictionary of promotion configurations. (read-only)

@property (nonatomic, readonly) NSDictionary *promoConfigurations

Discussion
This property provides a quick and full list of EPZPromoConfiguration objects, each keyed with its configuration’s configKey value. It is a more verbose alternative to the promoKeys property, which simply provides a list of configuration keys.

Declared In
EPZPromoLibrary.h



promoKeys

An array of promotion configuration keys. (read-only)

@property (nonatomic, readonly) NSArray *promoKeys

Discussion
This property provides a quick list of configuration keys available. It is a smaller alternative to the promoConfigurations property, which provides a more verbose set of data.

Declared In
EPZPromoLibrary.h



version

The version of the EPrizeMobileSDK. (read-only)

@property (nonatomic, readonly) float version

Discussion
This is a convenience property that returns the version number of the EPrizeMobileSDK framework you are using.

Declared In
EPZPromoLibrary.h



debug

A flag that can be set to enable NSLog output.

@property (nonatomic) BOOL debug

Discussion
This property can be set to YES to enable NSLog output for various error logging throughout the SDK code, if so desired. It is recommended that this only be enabled if you are experiencing problems with one or more of the methods in the SDK code, as a way to further inspect what the issue may be. It is not recommended to have this enabled for production-ready apps.

Declared In
EPZPromoLibrary.h


Class Methods

sharedLibrary

Returns the singleton library instance.

+ (EPZPromoLibrary *) sharedLibrary

Declared In
EPZPromoLibrary.h


Instance Methods

promotionConfigurationForKey:

Returns an instance of the EPZPromoConfiguration object, which contains information relevant to a promotion.

- (EPZPromoConfiguration *) promotionConfigurationForKey:(NSString *)key

Parameters

key
One of the configuration keys that is stored in the promoKeys property.

Discussion
This method lets you get an 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 EPZPromoConfiguration object, see the documentation for EPZPromoConfiguration.

Declared In
EPZPromoLibrary.h



fetchPromotionConfigurations:

Retrieves a list of promotion configurations from the HelloWorld servers.

- (void) fetchPromotionConfigurations:(void(^)(NSArray *data, NSError *error))callback

Parameters

callback
A block that is called upon completion of the fetch for promotion configurations. The block’s arguments are an NSArray of promotion configuration keys (when successful) an NSError (if unsuccessful).

Discussion
This method makes an asynchronous request to retrieve a list of promotion configuration keys, using the clientKey property value (which should be set in your App Delegate so it is ready to use when needed).

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 so:

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

Declared In
EPZPromoLibrary.h



launchPromotionForKey:

Calls the openURL method on the parent app’s UIApplication sharedApplication instance.

- (void) launchPromotionForKey:(NSString *)key

Parameters

key
One of the configuration keys that is stored in the promoKeys property.

Discussion
This is a convenience method to easily launch a promotion for a given key, using the device’s default web browser.

Note: It is recommended that you do not use this method, but rather create an instance of EPZPromoWebViewController and add 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 openInNativeBrowser value of NO.

Declared In
EPZPromoLibrary.h

Personal tools