Name: uphold-sdk-ios
Owner: Uphold
Description: Uphold iOS SDK
Created: 2015-06-08 09:32:10.0
Updated: 2018-05-23 14:22:18.0
Pushed: 2018-05-23 14:22:27.0
Size: 404
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Uphold is a next generation platform that allows anyone to transfer and exchange value for free, instantly and securely.
The Uphold SDK for iOS provides an easy way for developers to integrate iOS applications with the Uphold API.
* Xcode 8
* Swift 3
* Carthage or CocoaPods
Add to your Podfile
.
form :ios, '10.0'
frameworks!
use Uphold's production environment.
'UpholdSdk/Production'
use Uphold's sandbox environment:
d 'UpholdSdk/Sandbox'
Run pod install
.
Add to your Cartfile
.
ub "uphold/uphold-sdk-ios" ~> 0.17.0
Run carthage update --platform iOS
specifying the build configuration to use Uphold's different environments.
use Uphold's production environment.
hage update --platform iOS --configuration ProductionRelease
use Uphold's sandbox environment:
rthage update --platform iOS --configuration SandboxRelease
In order to learn more about the Uphold API, please visit the developer website.
To use the SDK you must first register an Application and obtain a unique CLIENT_ID
and CLIENT_SECRET
combination. We recommend your first app be registered in the Sandbox environment, so you can safely play around during development.
From the application page in your account you can get the client id
, client secret
, configure the redirect URI
and the desired scopes
.
In order to allow users to be re-directed back to the application after the authorization process, you?ll need to associate your custom scheme
with your app by adding the following keys into the Info.plist
file:
For instance, our demo application has the following configuration:
>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>uphold-demo</string>
</array>
</dict>
</array>
We start the authentication process by instantiating the UpholdClient and then calling the beginAuthorization
method:
LoginViewController.swift
upholdClient = UpholdClient()
authorizationViewController = upholdClient.beginAuthorization(self, clientId: CLIENT_ID, scopes: scopes, state: state)
In the AppDelegate
class you'll need to implement the method application(application: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool
that is called when the user completes the authorization process.
AppDelegate.swift
application(application: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
loginViewController.completeAuthorization(url)
return true
To complete the authorization process you'll need to call the completeAuthorization
method from the upholdClient
and get the user bearer token from the authentication response.
LoginViewController.swift
ldClient.completeAuthorization(authorizationViewController, clientId: CLIENT_ID, clientSecret: CLIENT_SECRET, grantType: "authorization_code", state: state, uri: url).then { (response: AuthenticationResponse) -> () in
// Get the user bearer token from the authenticationResponse.
To get the current user information, just instantiate the Uphold client with the user bearer token and then call the getUser()
function:
upholdClient = UpholdClient(bearertoken: bearerToken)
ldClient.getUser().then { (user: User) -> () in
/// The user information is available at the user object.
Note: Don't forget to add keychain sharing capabilities in your application's target inside the Capabilities
tab.
upholdClient = UpholdClient(bearerToken: bearerToken)
ldClient.getUser().then { (user: User) -> Promise<[Card]> in
return user.getCards()
n { (cards: [Card]) -> () in
/// Do something with the list of cards.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
.getCards().then { (cards: [Card]) -> () in
/// Do something with the list of cards.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
cardRequest: CardRequest = CardRequest(currency: "foo", label: "BTC", settings: CardSettings(position: 1, starred: true))
r just create a card without specifying the card settings.
et cardRequest: CardRequest = CardRequest(currency: "foo", label: "BTC")
.createCard(cardRequest).then { (card: Card) -> () in
/// Do something with the card.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
addressRequest: AddressRequest = AddressRequest(network: "bitcoin")
.createAddress(addressRequest).then { (address: Address) -> () in
/// Do something with the address of the card.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Instantiate the client. In this case, we don't need an
AUTHORIZATION_TOKEN because the Ticker endpoint is public.
upholdClient = UpholdClient()
Get tickers.
ldClient.getTickers().then { (rateList: [Rate]) -> () in
/// Do something with the rates list.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Or you could get a ticker for a specific currency:
Get tickers for BTC.
ldClient.getTickersByCurrency("BTC").then { (rateList: [Rate]) -> () in
/// Do something with the rates list.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
transactionDenominationRequest = TransactionDenominationRequest(amount: "1.0", currency: "BTC")
A transaction to a destination (card id, crypto address, email, phone number or username).
transactionTransferRequest = TransactionTransferRequest(denomination: transactionDenominationRequest, destination: "foo@bar.com")
.createTransaction(transactionTransferRequest).then { (transaction: Transaction) -> () in
/// Commit the transaction.
transaction.commit(TransactionCommitRequest("Commit message"))
ror({ (error: ErrorType) -> Void in
/// Do something with the error.
A transaction to a destination (card id, crypto address, email, phone number or username) with reference.
transactionTransferRequest = TransactionTransferRequest(denomination: transactionDenominationRequest, destination: "foo@bar.com", reference: "123456")
.createTransaction(transactionTransferRequest).then { (transaction: Transaction) -> () in
/// Commit the transaction.
transaction.commit(TransactionCommitRequest("Commit message"))
ror({ (error: ErrorType) -> Void in
/// Do something with the error.
A deposit from an ACH or SEPA account.
transactionDepositRequest = TransactionDepositRequest(denomination: transactionDenominationRequest, origin: "accountId")
.createTransaction(transactionDepositRequest).then { (transaction: Transaction) -> () in
/// Commit the transaction.
transaction.commit(TransactionCommitRequest("Commit message"))
ror({ (error: ErrorType) -> Void in
/// Do something with the error.
A deposit from a credit card.
transactionCardDepositRequest = TransactionCardDepositRequest(denomination: transactionDenominationRequest, origin: "creditCardId", securityCode: "1234")
.createTransaction(transactionCardDepositRequest).then { (transaction: Transaction) -> () in
/// Commit the transaction.
transaction.commit(TransactionCommitRequest("Commit message"))
ror({ (error: ErrorType) -> Void in
/// Do something with the error.
If you want to commit the transaction on the creation process, call the createTransaction
method with the first parameter set to true
.
.createTransaction(true, transactionRequest: transactionRequest)
Instantiate the client. In this case, we don't need an
AUTHORIZATION_TOKEN because the Ticker endpoint is public.
upholdClient = UpholdClient()
paginator: Paginator<Transaction> = client.getReserve().getTransactions()
Get the list of transactions.
nator.elements.then { (transactions: [Transaction]) -> () in
/// Do something with the list of transactions.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Get the next page of transactions.
nator.getNext().then { (transactions: [Transaction]) -> () in
/// Do something with the list of transactions.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Or you could get a specific public transaction:
Get one public transaction.
ldClient.getReserve().getTransactionById("a97bb994-6e24-4a89-b653-e0a6d0bcf634").then { (transaction: Transaction) -> () in
/// Do something with the list of transactions.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Instantiate the client. In this case, we don't need an
AUTHORIZATION_TOKEN because the Ticker endpoint is public.
upholdClient = UpholdClient()
Get the reserve summary of all the obligations and assets within it.
nt.getReserve().getStatistics().then { (reserveStatistics: [ReserveStatistics]) -> () in
/// Do something with the reserve statistics.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Some endpoints will return a paginator. Here are some examples on how to handle it:
Get public transactions paginator.
paginator: Paginator<Transaction> = client.getReserve().getTransactions()
Get the first page of transactions.
nator.elements.then { (transactions: [Transaction]) -> () in
/// Do something with the list of transactions.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Check if the paginator has a valid next page.
nator.hasNext().then { (hasNext: Bool) -> () in
/// Do something with the hasNext.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Get the number of paginator elements.
nator.count().then { (count: Int) -> () in
/// Do something with the count.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Get the next page.
nator.getNext().then { (transactions: [Transaction]) -> () in
/// Do something with the list of transactions.
ror { (error: ErrorType) -> Void in
/// Do something with the error.
Check the sample application to explore an application using the Uphold iOS SDK.
To build the sample application you need the Xcode. Steps to build:
Clone the repository.
Get the project dependencies:
hage bootstrap --platform iOS
Open the sample project SampleApplication.xcodeproj
.
Add keychain sharing capabilities.
Build and run the app from inside Xcode.
The sample application is configured to use the sandbox environment, make sure you use a sandbox account to perform the login.
Have you found a bug or want to suggest something? Please search the issues first and, if it is new, go ahead and submit it.
It will be awesome if you can help us evolve uphold-sdk-ios
. Want to help?