Documentation Index
Fetch the complete documentation index at: https://mintlify.com/frol/near-connect-ios/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide shows you how to set up NEAR Connect in your iOS app from scratch. You’ll learn how to configure the wallet manager, environment objects, and wallet UI sheet.The code examples on this page are extracted from the complete working example app included with NEAR Connect iOS SDK.
Complete App Setup
import SwiftUI
import NEARConnect
@main
struct NEARConnectExampleApp: App {
@StateObject private var walletManager = NEARWalletManager()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(walletManager)
}
}
}
Using
@StateObject ensures the wallet manager persists for the lifetime of your app and survives view updates.import SwiftUI
import NEARConnect
struct ContentView: View {
@EnvironmentObject var walletManager: NEARWalletManager
@State private var showError = false
@State private var errorMessage = ""
var body: some View {
NavigationView {
VStack(spacing: 30) {
headerView
if walletManager.isSignedIn, let account = walletManager.currentAccount {
// Show connected account UI
accountView(account)
} else {
// Show connect prompt
connectPrompt
}
}
.padding()
.navigationBarTitleDisplayMode(.inline)
// CRITICAL: Present WalletBridgeSheet when showWalletUI is true
.fullScreenCover(isPresented: $walletManager.showWalletUI) {
WalletBridgeSheet()
.environmentObject(walletManager)
}
.alert("Error", isPresented: $showError) {
Button("OK", role: .cancel) { }
} message: {
Text(errorMessage)
}
}
}
private var headerView: some View {
VStack(spacing: 16) {
Image(systemName: "link.circle.fill")
.font(.system(size: 80))
.foregroundStyle(
LinearGradient(
colors: [.blue, .purple],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
Text("NEAR Connect")
.font(.largeTitle)
.fontWeight(.bold)
Text("iOS Demo")
.font(.title2)
.foregroundColor(.secondary)
}
}
private func accountView(_ account: NEARAccount) -> some View {
VStack(spacing: 24) {
VStack(spacing: 16) {
Image(systemName: "person.circle.fill")
.font(.system(size: 60))
.foregroundColor(.green)
VStack(spacing: 8) {
Text("Connected")
.font(.headline)
.foregroundColor(.secondary)
Text(account.accountId)
.font(.title3)
.fontWeight(.semibold)
.multilineTextAlignment(.center)
}
HStack {
Image(systemName: "wallet.pass.fill")
.font(.caption)
Text(account.walletId)
.font(.caption)
}
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color.blue.opacity(0.1))
.cornerRadius(12)
}
.padding()
.background(
RoundedRectangle(cornerRadius: 20)
.fill(Color(uiColor: .systemBackground))
.shadow(color: .black.opacity(0.1), radius: 10, x: 0, y: 5)
)
Button(action: {
walletManager.disconnect()
}) {
Label("Disconnect", systemImage: "rectangle.portrait.and.arrow.right")
.font(.headline)
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.padding()
.background(Color.red)
.cornerRadius(12)
}
}
.padding()
}
private var connectPrompt: some View {
VStack(spacing: 20) {
Text("Connect your NEAR wallet to get started")
.font(.title3)
.multilineTextAlignment(.center)
.foregroundColor(.secondary)
.padding(.horizontal)
Button(action: { walletManager.connect() }) {
Label("Connect Wallet", systemImage: "wallet.pass")
.font(.headline)
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.padding()
.background(
LinearGradient(
colors: [.blue, .purple],
startPoint: .leading,
endPoint: .trailing
)
)
.cornerRadius(12)
}
.shadow(color: .blue.opacity(0.3), radius: 10, x: 0, y: 5)
}
.padding()
}
}
@EnvironmentObject
WalletBridgeSheet
WalletBridgeSheet is the critical component that handles the WebView bridge to NEAR wallets. It automatically shows when showWalletUI becomes true (when wallet interaction is needed). Connection State
isSignedIn to determine connection state and access currentAccount for account details.Key Properties and Methods
NEARWalletManager Properties
| Property | Type | Description |
|---|---|---|
isSignedIn | Bool | Whether a wallet is currently connected |
currentAccount | NEARAccount? | The currently connected account (if any) |
showWalletUI | Bool | Controls when to present the WalletBridgeSheet |
NEARWalletManager Methods
| Method | Description |
|---|---|
connect() | Initiates wallet connection flow |
disconnect() | Disconnects the current wallet |
NEARAccount Properties
Always use
fullScreenCover (not sheet) for the WalletBridgeSheet to ensure proper wallet UI presentation.Next Steps
Token Transfer
Learn how to send NEAR tokens
Smart Contracts
Call smart contract functions
Authentication
Implement sign-in with message signing
API Reference
Complete API documentation