We are excited to introduce the latest generation (currently in Beta) of Box Swift SDK Gen, designed to elevate the developer experience and streamline your integration with the Box Content Cloud.
With this SDK, you’ll have access to:
- Full API Support: The new generation of Box SDKs empowers developers with complete coverage of the Box API ecosystem. You can now access all the latest features and functionalities offered by Box, allowing you to build even more sophisticated and feature-rich applications.
- Rapid API Updates: Say goodbye to waiting for new Box APIs to be incorporated into the SDK. With our new auto-generation development approach, we can now add new Box APIs to the SDK at a much faster pace (in a matter of days). This means you can leverage the most up-to-date features in your applications without delay.
- Embedded Documentation: We understand that easy access to information is crucial for developers. With our new approach, we have included comprehensive documentation for all objects and parameters directly in the source code of the SDK. This means you no longer need to look up this information on the developer portal, saving you time and streamlining your development process.
- Enhanced Convenience Methods: Our commitment to enhancing your development experience continues with the introduction of convenience methods. These methods cover various aspects such as chunk uploads, classification, and much more.
- Seamless Start: The new SDKs integrate essential functionalities like authentication, automatic retries with exponential backoff, exception handling, request cancellation, and type checking, enabling you to focus solely on your application's business logic.
Embrace the new generation of Box SDKs and unlock the full potential of the Box Content Cloud.
- Box Swift SDK GENERATED
- Table of contents
- Installing
- Getting Started
- Integration Tests
- Questions, Bugs, and Feature Requests?
- Copyright and License
The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To add a dependency to your Xcode project, click on Xcode project file on Packages Dependencies
and click on the plus icon to add a package. Then enter the following repository url https://github.com/box/box-swift-sdk-gen.git and click next.
Alternatively you can add a dependency to the dependencies value of your Package.swift.
For detailed instructions, please see the official documentation for SPM.
Carthage is a decentralized dependency manager which builds your dependencies and provides you with binary frameworks.
To add a dependency to BoxSdkGen
, you need to add the following line to your Cartfile
:
git "https://github.com/box/box-swift-sdk-gen.git"
Then run:
carthage bootstrap --use-xcframeworks
And finally drag the built xcframework
from Carthage/Build into your project.
For more detailed instructions, please see the official documentation for Carthage.
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects.
To start using BoxSdkGen
with CocoaPods, you need to add BoxSdkGen
dependency to your Podfile
:
pod 'BoxSdkGen'
Then run the following command in your project directory:
$ pod install
Now open your [project].xcworkspace and build.
For more detailed instructions, please see the official documentation for Cocoapods.
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.
The SDK provides a BoxDeveloperTokenAuth
class, which allows you to authenticate using your Developer Token.
Use instance of BoxDeveloperTokenAuth
to initialize BoxClient
object.
Using BoxClient
object you can access managers, which allow you to perform some operations on your Box account.
The example below demonstrates how to authenticate with Developer Token and print names of all items inside a root folder.
import BoxSdkGen
let auth = BoxDeveloperTokenAuth(token: "DEVELOPER_TOKEN_GOES_HERE")
let client = BoxClient(auth: auth)
let items = try await client.folders.getFolderItems(folderId: "0")
if let entries = items.entries {
for entry in entries {
switch entry {
case let .fileMini(file):
print("file \(file.name!) [\(file.id)]")
case let .folderMini(folder):
print("folder \(folder.name!) [\(folder.id)]")
case let .webLinkMini(webLink):
print("webLink \(webLink.name!) [\(webLink.id)]")
}
}
}
The usage docs that show how to make calls to the Box API with the SDK can be found here.
We recommend, familiarizing yourself with the remaining authentication methods, uploading files and downloading files.
To run integration tests locally you will need a Custom App
created in the Box Developer
Console
with Server Authentication (Client Credentials Grant)
selected as authentication method.
Once created you can edit properties of the application:
- In section
App Access Level
selectApp + Enterprise Access
. You can enable allApplication Scopes
. - In section
Advanced Features
enableMake API calls using the as-user header
andGenerate user access tokens
.
Now select Authorization
and submit application to be reviewed by account admin.
To run integration tests, you need several environment variables specifying your account and the Box application you've created.
- Set the
CLIENT_ID
environment variable to its corresponding value from theConfiguration
tab in the sectionOAuth 2.0 Credentials
of your application. - Set the
CLIENT_SECRET
environment variable to its corresponding value from theConfiguration
tab in the sectionOAuth 2.0 Credentials
of your application. - Set the
ENTERPRISE_ID
environment variable to its corresponding value from theGeneral Settings
tab the sectionApp Info
of your application. - Set the
USER_ID
environment variable to its corresponding value from theGeneral Settings
tab the sectionApp Info
of your application. - Set the
BOX_FILE_REQUEST_ID
environment variable to the ID of file request already created in the user account,BOX_EXTERNAL_USER_EMAIL
with email of free external user which not belongs to any enterprise. - Set the
WORKFLOW_FOLDER_ID
envornment variable to the ID of the Relay workflow that deletes the file that triggered the workflow. The workflow should have a manual start to be able to start it from the API. - Set environment variable:
APP_ITEM_ASSOCIATION_FILE_ID
to the ID of the file with associated app item andAPP_ITEM_ASSOCIATION_FOLDER_ID
to the ID of the folder with associated app item.
To run integration tests locally:
swift test
Need to contact us directly? Browse the issues tickets! Or, if that doesn't work, file a new one and we will get back to you. If you have general questions about the Box API, you can post to the Box Developer Forum.
Copyright 2023 Box, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.