Full SDK documentation can be viewed at http://jawbone.github.io/UPPlatform_iOS_SDK/
This SDK provides an Objective-C interface for integrating iOS apps with the UP Platform. It handles authentication using OAuth 2.0 via a UIWebView and provides simple interfaces for making requests to the platform's REST endpoints.
The only requirements to start developing with the UP iOS SDK are OS X Mavericks, Xcode 5 and iOS 7. It is recommended that you upgrade to OS X Mavericks, Xcode 5 and iOS 7 if you haven't done so already.
You will need to have access to an existing Jawbone UP user account in order to authenticate with the UP Platform. New accounts can be created by going to jawbone.com/start/signup.
- Getting Started
- Documentation
- Unit Tests
- Additional Resources
- Terms of Service
- API Status
- Support
- Credits
- License
Sign into the Jawbone UP Developer Portal using your Jawbone UP account. If you do not have an account you can create one by going to jawbone.com/start/signup.
Register your organization by pressing "Manage Account".
Follow the instructions to create a new app and get your OAuth Client ID and App Secret keys that you will use to authenticate with the UP Platform.
Specify your custom redirect URI in the "OAuth Redirect URI" field or use the default value up-platform://redirect
.
You can download the latest iOS SDK release via the link below or clone it directly from this GitHub repository.
Option 1: Download UP iOS SDK v1.0.0 (November 2013)
https://github.com/Jawbone/UPPlatformSDK/releases/tag/v0.1-alpha
Option 2: Clone this repository from GitHub
git clone [email protected]:Jawbone/UPPlatformSDK.git
The Jawbone UP iOS SDK comes with a sample iOS app that you can use to authenticate with the UP Platform and start interacting with a Jawbone UP account.
You can find and open the PlatformTest project in UPPlatformSDK/HelloUP/HelloUP.xcodeproj
.
- Drag
UPPlatformSDK.framework
into Frameworks group inside your Xcode project or workspace.
- Under Build Settings, add
-ObjC
to Other Linker Flags.
That's it!
Now just add #import <UPPlatformSDK/UPPlatformSDK.h>
wherever you want to use the SDK in your project.
Authentication is handled using the shared UPPlatform
object. To start a new session, use the startSessionWithClientID:clientSecret:authScope:completion:
method.
NOTE: If you specified a custom redirect URI for your app in the Jawbone UP Developer Portal you can specify it using the startSessionWithClientID:clientSecret:authScope:redirectURI:completion:
method instead.
[[UPPlatform sharedPlatform] startSessionWithClientID:@"MY_CLIENT_ID"
clientSecret:@"MY_CLIENT_SECRET"
authScope:(UPPlatformAuthScopeExtendedRead | UPPlatformAuthScopeMoveRead)
completion:^(UPSession *session, NSError *error) {
if (session != nil) {
// Your code to start making API requests goes here.
}
}];
NOTE: Possible UPPlatformAuthScope values can be found in UPPlatform.h
.
Once a valid session has been established, there are a few ways to create API requests. You can use either the provided objects that encapsulate most of the available endpoints, or you can create custom requests. The API Objects are the simplest way to create requests to the REST platform. They take creating the network requests and parsing the resulting JSON into NSObject
s.
To validate that an existing session is still valid, call validateSessionWithCompletion:
. If the session
object passed to the completion block is not nil
, the session is valid and API requests can be made. This method is useful in order to prevent any API requests from unexpectedly returning a 401 Unauthorized
response when the user's access token is not valid.
To enable additional logging for network requests and responses being sent and received via the SDK, [UPPlatform SharedPlatform].enableNetworkLogging
should be set to YES.
NOTE: All units (weight, distance) are in metric.
[UPUserAPI getCurrentUserWithCompletion:^(UPUser *user, UPURLResponse *response, NSError *error) {
// Your code to process returned UPUser object.
}];
[UPUserAPI getFriendsWithCompletion:^(NSArray *friends, UPURLResponse *response, NSError *error) {
// Your code here to process an array of UPUser objects.
}];
[UPUserAPI getTrendsWithEndDate:nil
rangeType:UPUserTrendsRangeTypeDays
rangeDuration:10U
bucketSize:UPUserTrendsBucketSizeDays
completion:^(NSArray *trends, UPURLResponse *response, NSError *error) {
// Your code here to process an array of UPTrend objects.
}];
[UPMoveAPI getMovesWithLimit:10U completion:^(NSArray *moves, UPURLResponse *response, NSError *error) {
// Your code here to process an array of UPMove objects.
}];
You can request a visualization of the user's moves data as a 560x300 PNG image with a transparent background.
[UPMoveAPI getMoveGraphImage:move completion:^(UIImage *image) {
// Your code here to process the graph image.
}];
[UPWorkoutAPI getWorkoutsWithLimit:10U completion:^(NSArray *workouts, UPURLResponse *response, NSError *error) {
// Your code here to process an array of UPWorkout objects.
}];
We can start by creating a new workout event.
UPWorkout *workout = [UPWorkout workoutWithType:UPWorkoutTypeBike
startTime:startTime
endTime:endTime
intensity:UPWorkoutIntensityEasy
caloriesBurned:@300];
workout.distance = @7;
workout.imageURL = @"YOUR_IMAGE_URL.png";
We can then post this workout event to the user's feed.
[UPWorkoutAPI postWorkout:workout completion:^(UPWorkout *workout, UPURLResponse *response, NSError *error) {
// Your completion code here.
}];
You can request a visualization of the user's workout data as a 560x300 PNG image with a transparent background.
[UPWorkoutAPI getWorkoutGraphImage:workout completion:^(UIImage *image) {
// Your code here to use the graph image.
}];
[UPSleepAPI getSleepsWithLimit:10U completion:^(NSArray *sleeps, UPURLResponse *response, NSError *error) {
// Your code here to process an array of UISleep objects.
}];
You can request a visualization of the user's sleep data as a 560x300 PNG image with a transparent background.
[UPSleepAPI getSleepGraphImage:sleep completion:^(UIImage *image) {
// Your code here to handle the graph image.
}];
[UPMealAPI getMealsWithLimit:5U completion:^(NSArray *meals, UPURLResponse *response, NSError *error) {
// Your code here to process the meals array.
}];
Meal events should be created with one or more meal items. To create a new meal event, we start by specifying nutritional information for a single meal item.
UPMealNutritionInfo *info = [[UPMealNutritionInfo alloc] init];
info.calories = @130;
info.sugar = @30;
info.carbohydrates = @10;
info.calcium = @80;
Afterwards, we create a new meal item and set its nutritional information.
UPMealItem *item = [UPMealItem mealItemWithName:@"Granola Bar"
description:@"A fancy granola bar."
amount:@1
measurementUnits:@"bar"
servingType:UPMealItemServingTypePlate
foodType:UPMealItemFoodTypeBrand
nutritionInfo:info];
Then, we create a new meal event that will hold the meal item we had just created.
UPMeal *meal = [UPMeal mealWithTitle:@"Delicious Granola Bar"
note:@"It was tasty"
items:@[item]];
meal.photoURL = @"YOUR_PHOTO_URL.png";
Finally, let's post a new event on the user's feed with our new meal!
[UPMealAPI postMeal:meal completion:^(UPMeal *meal, UPURLResponse *response, NSError *error) {
// Your code here to process the meal object.
}];
[UPMealAPI getMealDetails:meal completion:^(UPMeal *meal, UPURLResponse *response, NSError *error) {
// Your code here to process the meal object.
}];
[UPMoodAPI getCurrentMoodWithCompletion:^(UPMood *mood, UPURLResponse *response, NSError *error) {
[self showResults:mood];
}];
To set the user's mood we first need to create a new UPMood object.
UPMood *newMood = [UPMood moodWithType:UPMoodTypePumpedUp title:@"I'm pumped!"];
Then, we can post the new UPMood object to the user's feed.
[UPMoodAPI postMood:newMood completion:^(UPMood *mood, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPMoodAPI getCurrentMoodWithCompletion:^(UPMood *mood, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPMoodAPI deleteMood:mood completion:^(id result, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
To create a new cardiac event we first need to create a new UPCardiacEvent object.
UPCardiacEvent *cardiacEvent = [UPCardiacEvent eventWithTitle:@"Run"
heartRate:@120
systolicPressure:@120
diastolicPressure:@80
note:@"Good weather."
image:nil];
Then, we can post the new UPCardiacEvent object to the user's feed.
[UPCardiacEventAPI postCardiacEvent:cardiacEvent
completion:^(UPCardiacEvent *event, UPURLResponse *response, NSError *error) {
}];
[UPCardiacEventAPI getCardiacEventsWithCompletion:^(NSArray *results, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPCardiacEventAPI deleteCardiacEvent:event
completion:^(id result, UPURLResponse *response, NSError *error) {
// Your code goes here.
}};
To create a new body event we first need to create a new UPBodyEvent object.
UPBodyEvent *bodyEvent = [UPBodyEvent eventWithTitle:@"Morning start."
weight:@70
bodyFat:@0.14f
leanMass:@29.5f
bmi:@18.5f
note:@"Good progress."
image:nil];
Then, we can post the new UPBodyEvent object to the user's feed.
[UPBodyEventAPI postBodyEvent:bodyEvent
completion:^(UPBodyEvent *event, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPBodyEventAPI getBodyEventsWithCompletion:^(NSArray *results, UPURLResponse *response, NSError *error)
// Your code goes here.
}];
[UPBodyEventAPI deleteBodyEvent:bodyEvent
completion:^(id result, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
To create a new generic event we first need to create a new UPGenericEvent object.
UPGenericEvent *genericEvent = [UPGenericEvent eventWithTitle:@"Good deed."
verb:@"Done well."
attributes:@{}
note:@"Indeed."
image:nil];
Then, we can post the new UPGenericEvent object to the user's feed.
[UPGenericEventAPI postGenericEvent:genericEvent
completion:^(UPGenericEvent *event, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPGenericEventAPI getGenericEventsWithCompletion:^(NSArray *results, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
[UPGenericEventAPI deleteGenericEvent:genericEvent
completion:^(id result, UPURLResponse *response, NSError *error) {
// Your code goes here.
}];
Custom API Requests can also be made using the UPURLRequest
object, which is what the API Objects also use. This allows you to make a request to any endpoint, giving any parameters, and receiving a resulting JSON object. Here are a few examples:
UPURLRequest *request = [UPURLRequest getRequestWithEndpoint:@"nudge/api/users/@me"
params:nil];
[[UPPlatform sharedPlatform] sendRequest:request
completion:^(UPURLRequest *request, UPURLResponse *response, NSError *error) {
// The resulting response.data is an NSDictionary with the JSON results.
}];
NSDictionary *params = @{
@"title": @"I feel great!",
@"sub_type": @1,
@"tz": [NSTimeZone localTimeZone].name
};
UPURLRequest *request = [UPURLRequest postRequestWithEndpoint:@"nudge/api/users/@me/mood"
params:params];
[[UPPlatform sharedPlatform] sendRequest:request
completion:^(UPURLRequest *request, UPURLResponse *response, NSError *error) {
// The resulting response.data is an NSDictionary describing the created mood.
}];
The SDK ships with a suite of XCTest unit tests that cover the API functionality. You can run the tests by opening the UP iOSK SDK project in Xcode 5 and pressing ⌘ + Shift + U.
You can find additional Jawbone UP Platform documentation at https://jawbone.com/up/developer.
Key principles governing the use of the UP API:
- The data belongs to the user. We are stewards of the data and have an obligation to protect it and use it responsibly.
- Data can only be collected with explicit user permission. Only collect what you need and only use it as you say you will.
- User must have a mechanism to disable access and to request that any collected data be deleted.
- Use of the UP API is governed by the UP API Terms Of Service.
By using the API, you agree to the TOS, available for your review.
Please visit UP Platform's status page to see the platform status updated in real-time.
Follow us on Twitter @JawboneDev to get the latest news and updates regarding the API.
Contact the developer support team by sending an email to [email protected].
Andy Roth
Senior Software Engineer
Jawbone
Usage is provided under the Apache License (v2.0). See LICENSE for full details.