TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | Apache 2 |
ReleasedLast Release | Mar 2017 |
Maintained by Eric Horacek.
Depends on: | |
AFNetworking | ~> 3.0 |
AFOAuth2Manager | ~> 3.0 |
libextobjc/EXTScope | >= 0 |
Note: This SDK is in alpha. Please try it out and send us your feedback!
The Automatic SDK is the best way to build iOS apps powered by Automatic.
With the Automatic iOS SDK, your users can log in to your app with their Automatic accounts. Think Facebook or Twitter login—but rather than bringing a users' social graph, instead unlocking a wealth of automotive data that you can use to supercharge your app.
Pictured: your app's new login screen
Once a user approves your app's request to access their data, your app could:
We can't wait to see what you build. Let's get to it!
automatic-[client-id]://oauth
.Integrate the Automatic iOS SDK. We recommend using CocoaPods, which makes integration as easy as adding
pod "AutomaticSDK", "0.0.1"
to your Podfile.
Configure your app to use the URL scheme you decided on
earlier. You can do this by adding this to your Info.plist
file. If your
Client ID was for example 123abc
, it would look like this:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>automatic-123abc</string>
<key>CFBundleURLSchemes</key>
<array>
<string>automatic-123abc</string>
</array>
</dict>
</array>
Create an instance of AUTClient
with your Client ID and Client Secret.
AUTClient *client = [[AUTClient alloc] initWithClientID:@"CLIENT_ID" clientSecret:@"CLIENT_SECRET"];
When you're ready to authorize your app with the Automatic API, call
-[AUTClient authorizeWithScopes:success:failure:]
to have the SDK open
Safari for you:
[self.client
authorizeWithScopes:AUTClientScopesTrip | AUTClientScopesLocation
success:^{
NSLog(@"🎉 Your app is now authorized. 🎉");
}
failure:^(NSError *error) {
NSLog(@"Failed to log in with error: %@", error.localizedDescription);
}];
Implement -application:openURL:sourceApplication:annotation:
to
handle your custom URL scheme that Automatic will redirect to, once a user
has given your app access:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)URL sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([self.client handleOpenURL:URL]) {
return YES;
}
return NO;
}
Once your client is authorized, you can store its credentials in the keychain
using AFOAuthCredential
:
[AFOAuthCredential storeCredential:self.client.credential withIdentifier:@"credential"];
You can now make requests against the Automatic API on behalf of your user:
[self.client
fetchTripsForCurrentUserWithSuccess:^(NSDictionary *page){
NSArray *trips = page[@"results"];
// Do something cool with the trip data here.
}
failure:^(NSError *error){
NSLog(@"Something went wrong.");
}];