Ramp iOS SDK is a library that allows you to easily integrate Ramp into your iOS app and communicate with it.
The quickest way to get started is by following this tutorial.
At the time of this writing the SOLANA_KIN asset is not listed on Ramp's test enviroment. This demo connects directly to the production environment in order to show KIN as an option.
To switch your demo to the test environment you need to specify a test network.
Example:
configuration.url = "https://ri-widget-staging.firebaseapp.com/"
In your Podfile
source 'https://github.com/passbase/zoomauthentication-cocoapods-specs.git'
source 'https://github.com/passbase/cocoapods-specs.git'
source 'https://github.com/passbase/microblink-cocoapods-specs.git'
target 'kin-ios-ramp-demo' do
use_frameworks!
pod 'Ramp', :git => '[email protected]:RampNetwork/ramp-sdk-ios.git', :tag => '2.0.0'
end
On your demo folder's root, install the pod files. This will bring the Ramp SDK into your project
pod install
Once the pods are installed, open the generated xcworkspace file.
Press the play icon to start the demo app
Press the Purchase Kin button, follow the on-screen instructions to finish up your purchase.
To start, add Ramp to your ViewController, Line 11 on the Demo.
import Ramp
On the ViewController.swift file (Line23) define the information we will pass to the Ramp SDK
@IBAction func showRamp(_ sender: UIButton) {
let address = kin?.address()
var configuration = Configuration()
configuration.userAddress = address
configuration.selectedCountryCode = "CA"
configuration.swapAsset = "SOLANA_KIN"
let ramp = try! RampViewController(configuration: configuration)
ramp.delegate = self
present(ramp, animated: true)
}
This passes the wallet address set on the Kin.swift file
let address = kin?.address()
Then we set other properties for the Ramp SDK to use.
configuration.userAddress = address
configuration.selectedCountryCode = "CA"
configuration.swapAsset = "SOLANA_KIN"
For a comprehensive list of options check Ramp's guide
Define a button to trigger Ramp (Line 150 on the ViewController.swift file)
private let getRamp: UIButton = {
let button = UIButton()
button.backgroundColor = .black
button.setTitleColor(
.white,
for: .normal
)
button.setTitleColor(
.gray,
for: .disabled
)
button.setTitle(
"Purchase Kin",
for: .normal
)
button.titleLabel?.textAlignment = .center
button.addTarget(
self,
action: #selector(showRamp),
for: .touchUpInside
)
return button
}()
private var getRampButtonFrame: CGRect {
let width: CGFloat = 200.0
let height: CGFloat = 50.0
return CGRect(
x: view.bounds.width / 2.0 - width / 2.0,
y: addToTestBalanceButtonFrame.maxY + 80.0,
width: width,
height: height
)
}
Add the subView of our button (Line 201 in the demo)
view.addSubview(getRamp)
Add the button to the subview layouts (Line 209 in the demo)
getRamp.frame = getRampButtonFrame
getRamp.layer.cornerRadius = getRampButtonFrame.height / 2.0
Then to finish the implementation, add the RampDelegate protocol. Ramp's SDK requires three required methods to be added (Line 351)
extension ViewController: RampDelegate {
func ramp(_ rampViewController: RampViewController, didCreatePurchase purchase: RampPurchase, purchaseViewToken: String, apiUrl: URL) {}
func rampPurchaseDidFail(_ rampViewController: RampViewController) {}
func rampDidClose(_ rampViewController: RampViewController) {}
}