TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | BSD |
ReleasedLast Release | Dec 2014 |
Maintained by Unclaimed.
Depends on: | |
AFNetworking | ~> 1.2.0 |
NXOAuth2Client | ~> 1.2.0 |
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.
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];
[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.
self.runKeeper = [[[RunKeeper alloc] initWithClientID:kRunKeeperClientID clientSecret:kRunKeeperClientSecret] autorelease];
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.
In your application delegate:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
[self.runKeeper handleOpenURL:url];
return TRUE;
}
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];
}
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