Giter Club home page Giter Club logo

runkeeper-ios's Introduction

RunKeeper-iOS

RunKeeper-iOS provides an Objective C wrapper class for accessing the RunKeeper Health Graph API from iOS 4.0 or newer.

RunKeeper-iOS was developed for use in our iPhone fitness app "Running Intensity". It is meant to be general, but is built primarily for a Running app. The API is NOT fully supported, but more will be added based on our own needs or the requests of others.

Dependencies

  • ASI HTTP Request - Used for the underlying network access
  • SBJson - Needed for parsing the response from bit.ly
  • OAuth2Client - Used for OAuth2 access to RunKeeper API
  • You will also need to register for a RunKeeper account, create an app, and get your tokens

Example Usage

Saving GPS Points

The RunKeeper will automatically create a correctly timestamped path for you if you post notifications.

RunKeeperPathPoint *point = [[[RunKeeperPathPoint alloc] initWithLocation:newLocation ofType:kRKGPSPoint] autorelease];
[[NSNotificationCenter defaultCenter] postNotificationName:kRunKeeperNewPointNotification object:point];

Posting a Run

[self.runKeeper postActivity:kRKRunning start:[NSDate date] 
              distance:[NSNumber numberWithFloat:10000]
              duration:[NSNumber numberWithFloat:[self.endTime timeIntervalSinceDate:self.startTime] + elapsedTime]
              calories:nil 
             heartRate:nil 
                 notes:@"What a great workout!" 
                  path:self.runKeeper.currentPath
               success:^{
                   UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Success" 
                                                                    message:@"Your activity was posted to your RunKeeper account."
                                                                   delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
                   [alert show];
                   
               }
                failed:^(NSError *err){
                    NSString *msg = [NSString stringWithFormat:@"Upload to RunKeeper failed: %@", [err localizedDescription]]; 
                    UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Failed" 
                                                                     message:msg
                                                                    delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
                    [alert show];
                }];

See more examples in the attached sample project.

Getting Started

Create a RunKeeper Instance with your Secret Keys

self.runKeeper = [[[RunKeeper alloc] initWithClientID:kRunKeeperClientID clientSecret:kRunKeeperClientSecret] autorelease];

Register a URL Scheme

Your URL Scheme is constructed by taking your RunKeeper ClientID and prepending "rk" --- an example is "rk055cac1c950b46e6ac7910d62800a854". The URL scheme is registered in your app's Info.plist file in order to receive redirects from OAuth2.

Handle the Redirect

In your application delegate:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  
  [self.runKeeper handleOpenURL:url];
  return TRUE;
}

Authorize the User

You begin by trying to connect to RunKeeper. If the user previously authorized the app and the access token, is still available, the connection will happen immediately and without any intervention:

[[AppData sharedAppData].runKeeper tryToConnect:self];

If the user has not granted authorization OR the access token has been lost/deleted, your delegate method needsAuthentication will be called. In this method, you can request authorization via OAuth.

- (void)needsAuthentication {
  [[AppData sharedAppData].runKeeper tryToAuthorize];
}

More Info

Check out the sample app to see a very simple integration.

Feel free to add enhancements, bug fixes, changes and provide them back to the community!

Thanks,

Reid van Melle

runkeeper-ios's People

Contributors

rvanmelle avatar

Stargazers

Aleksandar Vacić avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.