Polar-iOS-SDK 0.1.0

Polar-iOS-SDK 0.1.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Dec 2014

Maintained by Jeff Cole.




Example of Polar iOS SDK integration

The Polar iOS SDK allows you to use Polar Polls inside your own iOS app. (Read more about integrating Polar Polls.).

When you initialize an instance of Polar, it creates a UIWebView that loads embedded Polar polls. You can access this UIWebview via the pollView attribute. Simply add this UIWebView to your app in any way you like. Note that the minimum recommended size for the pollView UIWebView is 300x300.

Installation

Or, simply copy Polar.h and Polar.m into your project: Polar.h Polar.m

Example project

To run the example project, clone the repo, and run pod install from the Example directory first. Then, open the project by opening the file Example/PolarExample.xcworkspace.

Usage

Example code:

// replace this with the username for your Polar account
NSString *polarUserName = @"jcole";

// instantiate polar instance and add to view
Polar *polar = [[Polar alloc] init:polarUserName environment:PolarEnvironmentProduction];
[self.view addSubview:polar.pollsView];

// set the frame for your embed: 300x300 minimum recommended
[polar.pollsView setFrame:CGRectMake(0, 30, 320, 320)];

// load your polls
[polar loadPollSet:@926]; // example of a poll set
// [polar loadPoll:@98779]; // example of a single poll

// act as delegate for Polar activity (e.g. polls loaded, user voted, polls navigated)
// note: make sure in your controller interface, your controller implements PolarDelegate, e.g:
// @interface PolarExampleViewController : UIViewController <PolarDelegate>
polar.delegate = self;

Polar Class API

Initialize

Initialize the instance of Polar. The username argument comes from the Polar website account that you are publishing on behalf of. All analytics and results for these embeds will show up in the website when you log in as this user. The environment should specify either test or production.

- (id)init:(NSString *)username environment:(PolarEnvironment)polarEnvironment;
Param Description
username User's Polar username or email. Case sensitive.
polarEnvironment Whether to use the production environment (PolarEnvironmentProduction) or test environment PolarEnvironmentTest.

Load and display a single poll

- (void)loadPoll:(NSNumber*)pollID;
Param Description
pollID The ID of the poll to load.

Load and display a poll set

- (void)loadPollSet:(NSNumber*)pollSetID;
Param Description
pollSetID The ID of the poll set to load.

Get the unique identifier for the viewing user

This identifier is uniquely generated for each device. It is stored in NSUserDefaults, so it will be persistent across sessions.

+ (NSString *)viewerID;

Reset the unique identifier for the viewing user

In case you want to reset the uniquely generated identifier for this user (for example, for testing, or when your user logs out of your application).

+ (void)resetViewerID;

Get the ID of the current poll being displayed

Get the ID for the current poll being displayed.

- (NSString *)getCurrentPollID;

Get the UIWebView containing the embedded polls

This UIWebView loads an iFrame containing the self-contained embedded poll components.

- (UIWebView *)pollsView;

Callbacks

Polar will notify your app when the polls have finished loading, the user has voted, or the user has navigated to a new poll. To register for these, have your controller or other object implement the PolarDelegate method. For example:

@interface PolarExampleViewController : UIViewController <PolarDelegate>

Then, set your object as a delegate for the polar instance. For example:

polar.delegate = self;

Then, have your object implement any of the following callback delegate methods:

- (void)pollsLoaded {
    NSLog(@"polls loaded");
}

- (void)userVoted {
    NSLog(@"user voted");
}

- (void)userNavigated {
    NSLog(@"user navigated");
}

Test and Production environments

You can run Polar against either the environment PolarEnvironmentTest or PolarEnvironmentProduction:

Our production website:

https://polarb.com

For testing, user our staging servers:

https://polar-rails-staging.herokuapp.com

All content on each website should be available when using the respective environment targets. Consider PolarEnvironmentTest to be a sandbox that you can play in.

You will need to sign up at a polar account on each environment you wish to use:

Create a production account: http://polarb.com/join

Create a test account: https://polar-rails-staging.herokuapp.com/join

Author

Jeff Cole, [email protected]

License

Polar-iOS-SDK is available under the MIT license. See the LICENSE file for more info.