iOS ECR SDK
Purpose
The NamiECRSDK framework provides native Swift/Objective‑C integration for iOS and iPadOS applications. It enables secure communication with Nami payment terminals over TCP/IP (Wi‑Fi) or Bluetooth, using callback‑based communication rather than raw socket handling.
Prerequisites
- macOS with Xcode 14+
- Swift 5.7+
- iOS 13.0 or later
- Nami terminal connected via Wi‑Fi
Connection Example
import NamiECRSDK
class PaymentManager: SocketConnectionDelegate {
func connectToTerminal() {
ECRDataManager.shared.connectionMode = .tcpip
ECRDataManager.shared.cashRegisterNumber = "ECR001"
ECRTransactionManager.shared.connectTCP(
ip: "192.168.0.102",
port: 8888,
delegate: self
)
}
func didConnect() { print("Connected") }
func didDisconnect() { print("Disconnected") }
func didFailToConnect(error: Error) { print("Error: \(error)") }
}
Performing Transactions
ECRTransactionManager.shared.doTransaction(
dataArray: [date, ecrRefNo, amount] as NSArray,
selectedTransactionType: 0, // Purchase
onCompletion: { success, response in
print(success ? "Approved" : "Declined")
}
)
Transaction Flow
connectTCP() → Register (17) → Start Session (18) → doTransaction() → onCompletion
⚠️ Legacy vs Adapter Separation
- Legacy ECR integrations require Register (17) and Start Session (18).
- Adapter/Middleware integrations (Local REST API, Cloud REST API) do not require these steps.
Request and Response Details
- Date (
ddMMyyHHmmss) - ECR Reference Number
- Amount (Integer in halalas, e.g.,
100 = SAR 1.00)
Responses return:
- Response Code (Approved/Failed)
- Approval Code
- Receipt Data
⚠️ Bluetooth Limitations
- Supported only on iOS 13+
- Requires successful device pairing before SDK connection
- Only one terminal can be paired per iOS device at a time
- Sessions may drop under poor signal conditions; TCP/IP is recommended for production
- Advanced flows (refunds, reversals) are not supported over Bluetooth
- Some terminals require updated firmware for stable Bluetooth sessions
Transaction Type Codes
| Code | Transaction Type |
|---|---|
| 0 | Purchase |
| 1 | Purchase with Naqd/Cashback |
| 2 | Refund |
| 3 | Authorization |
| 4 | Purchase Advice (Full) |
| 5 | Purchase Advice (Partial) |
| 6 | Auth Extension |
| 7 | Auth Void |
| 9 | Cash Advance |
| 10 | Reconciliation |
| 11 | Reversal |
| 15 | Bill Payment |
| 17 | Register (Legacy only) |
| 18 | Start Session (Legacy only) |
| 19 | End Session |
| 23 | Duplicate / Previous Txn |
| 24 | Check Status |
| 25 | Health Check |
Updated 10 days ago
