iOS

Setup

Before we get started building our web application, we need to complete a few set up steps.


Step 1: Sign Up For A Smartcar Account

Go to our Developer Dashboard to sign up with Smartcar.

Step 2: Retrieve Your API Credentials

Once you have made your account, you will notice you already have an application with API keys. You will need these keys to complete this tutorial.

Step 3: Configure Your Redirect URI

You will need to set a redirect_uri for your application. We will be using this in the next section. For iOS, we require the custom URI scheme to be in the format of “sc” + clientId + “://” + hostname. For now, you can just set it to “sc” + clientId + “://exchange”. For more information about redirect URI's with custom URI scheme, refer to our docs.

Step 4: Clone The Starter Kit

Make sure you have cloned this repo and installed the required dependencies -

  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
  • $
git clone https://github.com/smartcar/getting-started-ios-sdk.git
cd getting-started-ios-sdk/tutorial
pod install
open getting-started-ios-sdk.xcworkspace

First, set the following constants -

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
// getting-started-ios-sdk/Constants.swift

struct Constants {
    static let clientId = "<your-client-id>";
}

We will be setting up a server for later for our iOS application to communicate with. For now, let's assume our server is listening on http://localhost:8000 and store it as a constant.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
// getting-started-ios-sdk/Constants.swift

struct Constants {
    static let clientId = "<your-client-id>";
    static let appServer = "http://localhost:8000";
}
Note: If you want to run the Swift app without writing any code, follow along with the Readme.

Now that we've set up our application, let's learn more about Smartcar's authorization flow.