Configuration
Download the framework from
Import the framework into your projects
Steps:
In the project navigator, select your project.
Select the "General" tab.
Open "Framework, Libraries and Embedded Content" expander.
(optional) or you can just drag and drop the file to "Framework, Libraries and Embedded Content".
3. Add Bluetooth as "Bluetooth Always Usage Description" to your info
4. import StreampayConnectKit
import StreampayConnectKit
5. Define connectivity object
@StateObject var conn: Connectivity = Connectivity.shared
6. add this modifier at the end of the root view
.streampayConnectivity()
7. Add sessionDelegate in the main root
.onAppear {
conn.sessionDelegate = self
}
8. Start Purchase
conn.startPurchaseTransaction(amount: 300)
9. Add extension to root view
extension ContentView: TransactionSessionDelegate
{
func transactionSesison(didReciviedDataFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data received \(transaction)")
}
func transactionSession(didEndWithFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data error \(error)")
}
}
Functions
setupUI()
This function is used to show the setup UI of StreamPay connect
startPurchaseTransaction(amount: )
Purchase is used to send the amount to the other Device
conn.startPurchaseTransaction(amount: 300)
resetSetting()
The reset setting is used to reset all the settings.
$showUI
ShowUI is a Boolean to check if UI is opened or closed.
var uiStatus = conn.showUI // it will be true or false
Example
Please check the example
import SwiftUI
import StreampayConnectKit
struct ContentView: View {
@StateObject var connecetivity : Connectivity = .shared
var body: some View {
VStack(spacing: 30) {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
.onTapGesture {
connecetivity.startPurchaseTransaction(amount: 300)
}
Button("settings")
{
connecetivity.setupUI()
}
Text("Hello, world! \(Connectivity.name)")
}
.padding()
.streampayConnectivity()
.onAppear
{
connecetivity.sessionDelegate = self
}
}
}
extension ContentView: TransactionSessionDelegate
{
public func transactionSesison(didReciviedDataFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data received: \(transaction)")
}
public func transactionSession(didEndWithFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("error received: \(transaction)")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
import UIKit
import StreampayConnectKit
class ViewController: UIViewController {
@IBOutlet weak var btnClickable: UIButton!
var connectivity: Connectivity = Connectivity.shared
override func viewDidLoad() {
super.viewDidLoad()
connectivity.sessionDelegate = self
connectivity.hostingUIViewController = self
}
@IBAction func onTap(_ sender: Any) {
connectivity.setupUI()
btnClickable.titleLabel?.text = " ali "
}
@IBAction func btnStartTransaction(_ sender: Any) {
connectivity.startPurchaseTransaction(amount: 3922)
}
}
extension ViewController: TransactionSessionDelegate {
func transactionSesison(didReciviedDataFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data received \(transaction)")
}
func transactionSession(didEndWithFor transaction: StreampayConnectKit.RemoteTransaction?, withError error: Error?) {
print("err recived \(error)")
}
}