This open source iOS library allows you to integrate Geni into your own iOS application. The library is compatible with all iOS devices, including iPhone, iPad and iPod touch.
The SDK is fully self-contained and does not require any additional libraries.
Follow these steps to download the Geni iOS SDK to your computer:
-
Install git on your computer
-
Download Geni iOS SDK using the following command:
git clone git@github.com:geni/geni-ios-sdk.git
Before you proceed with your own application integration, try out our sample application. Our sample application demonstrates our authorization mechanism as well as allows you to download your max family.
The sample application is located here:
geni-ios-sdk/FamilyList/FamilyList.xcodeproj
Once you open the project file, make sure you do the following:
-
Visit www.geni.com/platform/apps and register your application. You will be given your application id and secret.
-
Open AppDelegate.m and replace YOUR_APPLICATION_ID with the value you got from the previous step.
-
Open FamilyList-Info.plist and replace YOUR_APPLICATION_ID with the value from the first step.
-
Run the application and click on the “Connect to Geni” button. Provide your Geni user login and then authorize your application.
-
Once you authorized your app, you will be taken back to the FamilyList sample application, which will present you with your max family.
Follow these instructions to integrate Geni iOS SDK into your application:
Open geni-ios-sdk/GeniSDK/GeniSDK.xcodeproj and drag the GeniSDK folder into your own application root. You can choose to either copy the folder into your application or link it as a source folder. If you keep it linked, you will be able to download the latest version of the SDK without having to re-copy the latest changes to your application.
Include GeniSDK in your application classes (where you need the Geni functionality):
import "GeniSDK.h"
Visit www.geni.com/platform/apps and register your application. You will be given your application id and secret.
Instantiate the Geni object:
Geni *geni = [[Geni alloc] initWithAppId:YOUR_APPLICATION_ID];
Replace the YOUR_APPLICATION_ID with the appropriate value you got from step 3. If you are planning to have more than one controller accessing Geni API, it is recommend that you keep the Geni object in your Application Delegate and make your Application Delegate implement the GeniSessionDelegate protocol.
Call authorization method to authorize your application:
[geni authorize:self];
The parameter of the authorize method expects an object that implements GeniSessionDelegate. The authorization mechanism uses OAuth framework that takes the user to a Safari web browser, where the user can login and authorize your application. Once the user has authorized your application, the browser will redirect the user back to your application.
In order for the iOS device to recognize the redirect call from the Safari browser and launch your application correctly, add the following property to your application’s plist file (you can open the file as source code and deal with XML directly):
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string></string> <key>CFBundleURLSchemes</key> <array> <string>geni[YOUR_APPLICATION_ID]</string> </array> </dict> </array>
Replace [YOUR_APPLICATION_ID] with the value you got from step 4. If your application id is 12345, your CFBundleURLSchemes will look like the following:
<string>geni12345</string>
When Safari browser redirects users back to your application, it will match the url from the previous step and call the following method in your Application Delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [geni handleOpenURL:url]; }
Make sure you add the above code to your Application Delegate so that Geni client receives the authorization code.
Geni client will process the URL it received in the previous step and call one of the following methods on the session delegate you specified in step 5.
- (void) geniDidLogin; - (void) geniDidNotLogin:(BOOL)cancelled;
At this point you will either have a user that has authorized your application or canceled the action. You can handle each case in the above methods. If the user has authorized your application, you may now call any Geni API methods.
You can make calls to the Geni server using any of the following methods:
- (GeniRequest*)requestWithPath:(NSString *)path andDelegate:(id <GeniRequestDelegate>)delegate; - (GeniRequest*)requestWithPath:(NSString *)path andParams:(NSMutableDictionary *)params andDelegate:(id <GeniRequestDelegate>)delegate; - (GeniRequest*)requestWithPath:(NSString *)path andParams:(NSMutableDictionary *)params andHttpMethod:(NSString *)httpMethod andDelegate:(id <GeniRequestDelegate>)delegate;
For example, the following code will return back the current user JSON object:
[geni requestWithPath:@"user" delegate:self];
All of the calls to the Geni API are made asynchronously using the callback mechanism and a GeniRequestDelegate protocol. GeniRequestDelegate has a number of optional methods, among them:
- (void)request:(GeniRequest *)request didLoad:(id)result; - (void)request:(GeniRequest *)request didFailWithError:(NSError *)error;
If the request was successful, the “didLoad” method will be called and a call value will be passed as a parameter. If the request failed, then “didFailWithError” will be called instead.
For the above example, your code may look something like this:
- (IBAction) loadCurrentUserInfo: (id) caller { [geni requestWithPath:@"user" delegate:self]; }
- (void)request:(GeniRequest *)request didLoadResponse:(GeniResponse *)response {
NSLog(@"Name: %@", [response valueForKey:@"name"]);
}
To logout from Geni, call the following method:
[geni logout:self];
The parameter must be an object that implements the GeniSessionDelegate protocol.
To get more information on available API, please visit www.geni.com/platform/developer/help