Latest 0.1.0
Homepage https://github.com/input-factory/polar-ios-sdk
License MIT
Platforms ios , requires ARC
Authors

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 300×300.

Installation

Polar-iOS-SDK is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Polar-iOS-SDK"

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

// to set the frame for your embed to fill the window:
[polar.pollsView setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

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

// 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.

Load and display a poll placement

- (void)loadPollPlacement:(NSString*)pollPlacementID;
Param Description
pollPlacementID The ID of the poll placement 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.

Latest podspec

{
    "name": "Polar-iOS-SDK",
    "version": "0.1.0",
    "summary": "An SDK for displaying Polar polls.",
    "description": "                       An SDK for displaying Polar polls.  For more details on Polar polls and integration, consult then                       [Polar integration docs](https://github.com/input-factory/polar-integration-docs)n",
    "homepage": "https://github.com/input-factory/polar-ios-sdk",
    "screenshots": "https://polar-api-docs-assets.s3.amazonaws.com/example-polar-ios-sdk.png",
    "license": "MIT",
    "authors": {
        "Jeff Cole": "[email protected]"
    },
    "source": {
        "git": "[email protected]:input-factory/polar-ios-sdk.git",
        "tag": "0.1.0"
    },
    "social_media_url": "https://twitter.com/polarpolls",
    "platforms": {
        "ios": null
    },
    "requires_arc": true,
    "source_files": "Classes"
}

Pin It on Pinterest

Share This