TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2016 |
SwiftSwift Version | 3.0 |
Maintained by Johan Drevet.
Depends on: | |
OAuthSwift | ~> 1.1.0 |
DCKeyValueObjectMapping | ~> 1.5 |
SAMKeychain | ~> 1.5.2 |
Withings-SDK-iOS provides an Objective-C interface for integrating iOS apps with the Withings API. It handles OAuth 1.0 authentication using OAuthSwift library.
For now, the SDK implements the following Withings API:
The following features will be added in the future:
Withings-SDK-iOS requires iOS 8.0 and above.
In order to use the API, you will need to register as a developer here to get a consumer key and secret. Note that you will also need to have an end-user Withings account to fetch data from.
Several third-party open source libraries are used within Withings-SDK-iOS:
Before any other call, set up the shared WithingsAPI
object with your application keys. For example, you can set up the SDK in the method application:didFinishLaunchingWithOptions:
in your AppDelegate.
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString *consumerKey = @"<Your consumer key>";
NSString *consumerSecret = @"<Your consumer secret>";
[[WithingsAPI sharedInstance] setUpWithConsumerKey:consumerKey consumerSecret:consumerSecret];
return YES;
}
To get your keys, register as a developer here.
During the OAuth 1.0 authentication process, the user will be redirect to a web page managed by Withings to authorize your application to access to his resources. Your application should be configured to handle the callback called at the end of the process.
In your AppDelegate, implement application:openURL:
and call handleOpenURL:
on the shared WithingsAPI
object.
// AppDelegate.m
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options
{
[[WithingsAPI sharedInstance] handleOpenURL:url];
return YES;
}
Do not forget the deprecated method to manage the callbacks on iOS 8.0.
// AppDelegate.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation
{
[[WithingsAPI sharedInstance] handleOpenURL:url];
return YES;
}
Request the user authorization by calling the following method. The user will be redirect to a web page provided by Withings to authorize your application to access to his resources.
// SomeViewController.h
[[WithingsAPI sharedInstance] requestAccessAuthorizationWithCallbackScheme:@"<Your application scheme>" presenterViewController:self success:^(NSString *userId) {
//Persist the user id to be able to request Withings API without requesting again the user authorization
} failure:^(WithingsError *error) {
//Manage the error
}];
Once you have user authorization, you can call any API provided by the API client. You can manage one or more instance of clients or simply use the instance of client held by the WithingsAPI
singleton.
For example, to get all the activities measures for an user, call:
// SomeViewController.h
[[WithingsAPI sharedInstance].measureAPIClient getActivitiesMeasuresForUser:@"<The user id>" success:^(NSArray<WithingsActivity *> *activitiesMeasures) {
//Process the results
} failure:^(WithingsError *error) {
//Manage the error
}
Johan Drevet
Withings-SDK-iOS is released under the MIT license. See LICENSE for details.