BoxSDK

Platforms License Swift Package Manager Carthage compatible CocoaPods compatible Build Status Coverage Status

Box Swift SDK

Installing the SDK

Step 1: Add to your Cartfile

git "https://github.com/box/box-ios-sdk.git" "limited-beta-release"

Step 2: Update dependencies

$ carthage update --platform iOS

Step 3: Drag the built framework from Carthage/Build/iOS into your project.

For more detailed instructions, please see the official documentation for Carthage.

Getting Started

To get started with the SDK, get a Developer Token from the Configuration page of your app in the Box Developer Console. You can use this token to make test calls for your own Box account.

import BoxSDK

let client = BoxSDK.getClient(token: "YOUR_DEVELOPER_TOKEN")
client.users.getCurrentUser() { result in
    switch result {
    case let .error(error):
        print("Error: \(error)")
    case let .success(user):
        print("\(user.name) (\(user.login)) is logged in")
    }
}

Sample Apps

OAuth2 Sample App

A sample app using OAuth2 Authentication can be downloaded as a zip file. This app demonstrates how to use the SDK to make calls, and can be run directly by entering your own credentials to log in.

To execute the sample app: Step 1: Run carthage

$ cd SampleApps/OAuth2SampleApp
$ carthage update --platform iOS

Step 2: Open Workspace

$ open OAuth2SampleApp.xcworkspace

Step 3: Insert your client ID and client secret

First, find your OAuth2 app’s client ID and secret from the Box Developer Console. Then, add these values to the sample app in the Constants.swift file in the sample app:

static let clientId = "YOUR CLIENT ID GOES HERE"
static let clientSecret = "YOUR CLIENT SECRET GOES HERE"

Step 4: Set redirect URL

Using the same client ID from the previous step, set the redirect URL for your application in the Box Developer Console to boxsdk-<<YOUR CLIENT ID>>://boxsdkoauth2redirect, where <<YOUR CLIENT ID>> is replaced with your client ID. For example, if your client ID were vvxff7v61xi7gqveejo8jh9d2z9xhox5 the redirect URL should be boxsdk-vvxff7v61xi7gqveejo8jh9d2z9xhox5://boxsdkoauth2redirect

Step 5: Insert your client ID to receive the redirect in the app

Open the Info.plist file in the sample app and find the key under URL Types --> Item 0 --> URL Schemes --> Item 0. Using the same client ID from the previous step, set the value for Item 0 to boxsdk-<<YOUR CLIENT ID>>, where <<YOUR CLIENT ID>> is replaced with your client ID. For example, if your client ID were vvxff7v61xi7gqveejo8jh9d2z9xhox5 the redirect URL should be boxsdk-vvxff7v61xi7gqveejo8jh9d2z9xhox5

location to add redirect URL scheme in Xcode

Step 6: Run the sample app

JWT Auth Sample App

A sample app using JWT Authentication can be downloaded as a zip file. This app demonstrates how to set up JWT authentication with a remote authorization service, and will not run until you provide the code to retrieve tokens.

To execute the sample app: Step 1: Run carthage

$ cd SampleApps/JWTSampleApp
$ carthage update --platform iOS

Step 2: Open Workspace

$ open JWTSampleApp.xcworkspace

Step 3: Insert your client ID and client secret

First, find your OAuth2 app’s client ID and secret from the Box Developer Console. Then, add these values to the sample app in the Constants.swift file in the sample app:

static let clientId = "YOUR CLIENT ID GOES HERE"
static let clientSecret = "YOUR CLIENT SECRET GOES HERE"

Step 4: Add code for retrieving access tokens

In the ViewController.swift file in the sample app, edit the obtainJWTTokenFromExternalSources() method:

func obtainJWTTokenFromExternalSources() -> DelegatedAuthClosure {
    return { uniqueID, completion in
        #error("Obtain a JWT Token from your own service or a Developer Token for your app in the Box Developer Console at https://app.box.com/developers/console and return it in the completion.")
        // The code below is an example implementation of the delegate function
        // Please provide your own implementation

        // ...
    }
}

Step 5: Run the sample app

License

Any use of this software is governed by the attached Box SDK Beta Agreement. If you do not accept the terms of the Box SDK Beta Agreement, you may not use this software.