Search…
⌃K
Links

iOS Integration

You can use Nearpay Connect in your IOS app

Configuration

  1. 1.
    Download the framework from Here
2. Import the framework into your projects
Steps:
  • In the project navigator, select your project.
  • Select your target.
  • Select the "General" tab.
  • Open "Framework , Libraries and Embedded Content" expander.
  • Click the + button.
  • Add file
  • (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 NearpayConnectKit
import NearpayConnectKit
5. Define connectivity object
@StateObject var conn: Connectivity = Connectivity.shared
6. add this modifier in the end of root view
.nearpayConnectivity()
7. Add sessionDelegate in 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: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data received \(transaction)")
}
func transactionSession(didEndWithFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data error \(error)")
}
}

Functions

setupUI()

This function is used to show the setupUI of Nearpay connect
conn.setupUI()

startPurchaseTransaction(amount: )

Purchase is used to send the amount to the other Device
conn.startPurchaseTransaction(amount: 300)

resetSetting()

Reset setting is used to reset all the settings .
conn.resetSetting()

$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
SwiftUI
UIkit
Without NearpayConnect UI
import SwiftUI
import NearpayConnectKit
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()
.nearpayConnectivity()
.onAppear
{
connecetivity.sessionDelegate = self
}
}
}
extension ContentView: TransactionSessionDelegate
{
public func transactionSesison(didReciviedDataFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data received: \(transaction)")
}
public func transactionSession(didEndWithFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("error received: \(transaction)")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
import UIKit
import NearpayConnectKit
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: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data recived \(transaction)")
}
func transactionSession(didEndWithFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("err recived \(error)")
}
}
import UIKit
import NearpayConnectKit
class ViewController: UIViewController {
@IBOutlet weak var btnClickable: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
Connectivity.shared.connectDelegate = self // get connectivity status
Connectivity.shared.sessionDelegate = self // get transaction result
Connectivity.shared.bluetoothScanDelegate = self // get scan result
}
@IBAction func onTap(_ sender: Any) {
// Connecting Local Network e.g Wifi , Ethernet ...
//Connectivity.shared.connectLocal(host: "192.168.103.154", port: 8080)
// Connecting Bluethooth
Connectivity.shared.scanBluetoothDevices()
}
@IBAction func btnStartTransaction(_ sender: Any) {
// Make Transaction
Connectivity.shared.startPurchaseTransaction(amount: 3922)
}
}
// Connectivity.shared.sessionDelegate
extension ViewController: TransactionSessionDelegate {
func transactionSesison(didReciviedDataFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("data recived \(transaction)")
}
func transactionSession(didEndWithFor transaction: NearpayConnectKit.RemoteTransaction?, withError error: Error?) {
print("err recived \(error)")
}
}
// Connectivity.shared.connectDelegate
extension ViewController: ConnectivityConnectDelegate
{
func connectivityConnect(didConnectFor: NearpayConnectKit.ConnectivitySetting) {
print("did connect")
}
func connectivityConnect(didCloseFor: NearpayConnectKit.ConnectivitySetting, withError error: Error?) {
print("did close")
}
func connectivityConnect(didFailFor: NearpayConnectKit.ConnectivitySetting, withError error: Error?) {
print("did fail")
}
}
// Connectivity.shared.bluetoothScanDelegate
extension ViewController: BluetoothScanDelegate
{
func bluetoothScan(didFoundDeviceFor serviceId: String, device: NearpayConnectKit.BluetoothDevice) {
Connectivity.shared.connectBluetoothDevice(device: device)
}
func bluetoothScan(didStopFor serviceId: String) {
print("did stop scanning ..")
}
func bluetoothScan(didStartFor serviceId: String) {
print("did started scanning ..")
}
func bluetoothScan(didRefreshListFor serviceId: String, list: [NearpayConnectKit.BluetoothDevice]) {
print("List refreshed total devices ... \(list.count)")
}
}