CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate Coinbase SDK into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'coinbase-official', '~> 4.0'
Then, run the following command:
$ pod install
If you want to use the RxSwift extensions for Coinbase SDK add:
pod 'coinbase-official/RxSwift', '~> 4.0'
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Coinbase SDK into your Xcode project using Carthage, specify it in your Cartfile:
github "coinbase/coinbase-ios-sdk"
Run carthage update to build the framework and drag the built CoinbaseSDK.framework into your Xcode project. If you want to use the RxSwift extensions for Coinbase SDK add RxCoinbaseSDK.framework into your project as well.
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding Coinbase SDK as a dependency is as easy as adding it to the dependencies value of your Package.swift.
If you want to use the RxSwift extensions for Coinbase SDK add to target’s dependencies: "RxCoinbaseSDK".
Important
Swift Package Manager currently does not support resources. Coinbase SDK requires additional resource files to work properly (Trusted SSL Certificates). If you want to use Swift Package Manager you should provide those resources manually.
You can find the required resources in Coinbase iOS SDK GitHub repository under Source/Supporting Files/PinnedCertificates path. Collect those files and add them to your project.
Using Xcode:
You should additionally configure CoinbaseSDK target.
In tab Build Phases add new phase by selecting New Copy File Phase.
Drag and Drop required resources to this phase.
Using console:
To provide the required resources you should copy them to a location with built files.
Example: If required files are located in directory Resources and you building for x86_64-apple-macosx10.10 platform in debug mode then resources can be copied with the command:
CoinbaseSDK provides wrappers that allow you to use it with RxSwift. To get more information about how to use it read page.
Examples
To see more details on how to work with CoinbaseSDK you can check sample app or read some Coinbase Examples.
Sample app
To be able to use Coinbase SDK iOS Example app you should setup OAuth2 application keys. You can get the required keys after creating Coinbase OAuth2 Application.
Log in to your Coinbase account and create a new OAuth2 application (or get an existing one).
In application details page you can get clientId, clientSecret and redirectUri.
Open Coinbase workspace then inside iOS Example project fill empty values for OAuth2ApplicationKeys in Source/Constants.swift file.
Register custom scheme used in your redirectURI. In Info.plist file add:
Coinbase iOS SDK
This library is deprecated.
Thank you all for your contributions.
Table of Contents
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
To integrate Coinbase SDK into your Xcode project using CocoaPods, specify it in your
Podfile:Then, run the following command:
If you want to use the RxSwift extensions for Coinbase SDK add:
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
To integrate Coinbase SDK into your Xcode project using Carthage, specify it in your
Cartfile:Run
carthage updateto build the framework and drag the builtCoinbaseSDK.frameworkinto your Xcode project. If you want to use the RxSwift extensions for Coinbase SDK addRxCoinbaseSDK.frameworkinto your project as well.Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the
swiftcompiler.Once you have your Swift package set up, adding Coinbase SDK as a dependency is as easy as adding it to the
dependenciesvalue of yourPackage.swift.And in the target where you want to use it:
If you want to use the RxSwift extensions for Coinbase SDK add to target’s
dependencies:"RxCoinbaseSDK".Important
Swift Package Manager currently does not support resources. Coinbase SDK requires additional resource files to work properly (Trusted SSL Certificates). If you want to use Swift Package Manager you should provide those resources manually.
You can find the required resources in Coinbase iOS SDK GitHub repository under
Source/Supporting Files/PinnedCertificatespath. Collect those files and add them to your project.Using Xcode:
You should additionally configure
CoinbaseSDKtarget. In tabBuild Phasesadd new phase by selectingNew Copy File Phase. Drag and Drop required resources to this phase.Using console:
To provide the required resources you should copy them to a location with built files.
Example: If required files are located in directory
Resourcesand you building forx86_64-apple-macosx10.10platform indebugmode then resources can be copied with the command:Basic usage
In source file where you want to use CoinbaseSDK add:
If you want to use the RxSwift extensions for CoinbaseSDK using not CocoaPods, please import RxCoinbaseSDK by adding the following line:
To use CoinbaseSDK you need to have an instance of
Coinbaseclass. You can create a newCoinbaseinstance:Or you can use convenience static instance:
Authentication
To work with resources which require authentication you should provide a valid access token to Coinbase instance.
Access token can be provided either directly by setting its value to
coinbase‘s property:or by passing it to the initializer:
If you do not provide an access token to the instance of Coinbase you can successfully work with only the next resources:
CurrenciesResourceExchangeRatesResourcePricesResourceTimeResourceGetting access token
To get an access token the Coinbase iOS SDK uses OAuth2 authentication.
You should call
configuremethod onoauthproperty of Coinbase instance to set all required properties before calling any authorization method:Then you can initiate OAuth flow by calling
beginAuthorizationIt will redirect user into Safari browser where they can authorize your application.
In
AppDelegateyou should handle redirection back by callingcoinbase.oauth.completeAuthorizationmethod insideapplication(_:open:options:)To get a detailed guide on how to use OAuth2 with CoinbaseSDK read Getting Acess Token.
Note
Coinbase instace for
completeAuthorizationcall should be the same as you used to callbeginAuthorizationmethod.Important
Access token lifetime is pretty short and after the expiration, it should be refreshed with the refresh token.
You can perform refresh manually or allow auto-refresh by calling
setRefreshStrategywithTokenRefreshStrategy.refreshon Coinbase instance.Reed more about
TokenRefreshStrategyin Token refreshing.RxSwift
CoinbaseSDK provides wrappers that allow you to use it with RxSwift. To get more information about how to use it read page.
Examples
To see more details on how to work with CoinbaseSDK you can check sample app or read some Coinbase Examples.
Sample app
To be able to use Coinbase SDK iOS Example app you should setup OAuth2 application keys. You can get the required keys after creating Coinbase OAuth2 Application.
clientId,clientSecretandredirectUri.iOS Exampleproject fill empty values forOAuth2ApplicationKeysinSource/Constants.swiftfile.redirectURI. InInfo.plistfile add:Note:
Make sure that you used the same URI scheme in
redirectURIconstant and yourInfo.plistfile.For example, if your
[redirect_uri_scheme]iscom.example.app, then your redirect URI can be:com.example.app://callbackTesting
To be able to run tests, you should download dependencies. To do so, run:
If you do not have Carthage installed, check the installation instructions.
After that, you can open
Coinbase.xcworkspaceand selectCoinbaseSDKtarget and hit ⌘+U to start testing.License
Coinbase is available under the Apache License 2.0. See LICENSE file for more info.