TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Maintained by Jeff Cole.
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.
Or, simply copy Polar.h
and Polar.m
into your project:
Polar.h
Polar.m
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.
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;
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 . |
- (void)loadPoll:(NSNumber*)pollID;
Param | Description |
---|---|
pollID | The ID of the poll to load. |
- (void)loadPollSet:(NSNumber*)pollSetID;
Param | Description |
---|---|
pollSetID | The ID of the poll set to load. |
This identifier is uniquely generated for each device. It is stored in NSUserDefaults, so it will be persistent across sessions.
+ (NSString *)viewerID;
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 for the current poll being displayed.
- (NSString *)getCurrentPollID;
This UIWebView loads an iFrame containing the self-contained embedded poll components.
- (UIWebView *)pollsView;
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");
}
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
Polar-iOS-SDK is available under the MIT license. See the LICENSE file for more info.