An iOS application based on Apple's Ultra Wideband (UWB) technology and MultipeerConnectivity that precisely detects nearby iOS devices and displays their distance and direction.
This documentation is available in multiple languages:
- πΊπΈ English (Current version)
- πΉπΌ ηΉι«δΈζ (Traditional Chinese)
View all available translations: Translation Index
- UWB Precise Ranging: Centimeter-level precision using U1 chip in iPhone 11 or newer models
- Direction Detection: Display precise azimuth and elevation angles relative to the local device
- Real-time Radar View: Visualize surrounding device positions
- Multi-device Support: Support simultaneous connections with up to 8 devices
- Interactive Radar: Scalable and draggable circular radar view
- Device List: Display detailed information of all detected devices
- Real-time Updates: Distance and direction data updated in real-time
- Status Indicators: Visual UWB connection status display
- Chat Room Invitations: Send chat invitations to nearby devices
- Local Notifications: Receive push notifications for chat invitations
- Message Transmission: Send text messages through established connections
- iPhone 11 or newer models (equipped with U1 chip)
- iOS 15.0 or later
- iPhone 11, 11 Pro, 11 Pro Max
- iPhone 12 series (12, 12 mini, 12 Pro, 12 Pro Max)
- iPhone 13 series and newer models
- iPhone 14 series and newer models
- iPhone 15 series and newer models
Note: Devices that don't support UWB will display appropriate alerts but can still use basic device discovery features.
- SwiftUI: Modern UI framework
- NearbyInteraction: Apple's UWB ranging framework
- MultipeerConnectivity: Inter-device network connections
- Combine: Reactive programming
- UserNotifications: Local notification supportDevice A Device B
ββ startAdvertising ββ startBrowsing
ββ startBrowsing ββ startAdvertising
β β
ββ Discover Device B ββ Discover Device A
ββ Send Connection Invitation βββ ββ Receive Invitation
β ββ Establish MCSession
ββ Exchange Discovery Token βββββ ββ Exchange Discovery Token
ββ Create NISession ββ Create NISession
ββ Start UWB Ranging ββββββββββββ ββ Start UWB Ranging
ββ Real-time Distance/Direction ββ Real-time Distance/Direction
vector-chat/
βββ Models/
β βββ NearbyDevice.swift # Device data model
β βββ ChatModels.swift # Chat-related data models (In development)
β βββ ChatInvitation.swift # Chat invitation model
βββ Services/
β βββ MCService.swift # MultipeerConnectivity service
β βββ NearbyInteractionManager.swift # UWB manager (Main ViewModel)
β βββ NIService.swift # NearbyInteraction service
β βββ ChatService.swift # Chat service (In development)
β βββ ChatManager.swift # Chat manager (In development)
β βββ ChatroomManager.swift # Chatroom manager (In development)
βββ Views/
β βββ ContentView.swift # Main view
β βββ RadarView.swift # Radar view component
β βββ DeviceRow.swift # Device list item
β βββ DeviceMarkerView.swift # Device marker for radar
βββ Utilities/
β βββ DebugLogger.swift # Debug logging utility
βββ Extensions/
βββ NINearbyObject+Extensions.swift # NearbyInteraction extensions
-
Clone the Project
git clone https://github.com/SArthurX/vector-chat cd vector-chat -
Open Xcode Project
open vector-chat.xcodeproj
-
Configure Developer Certificate
- Select your development team in Xcode
- Ensure proper Bundle Identifier is set
-
Build and Run
- Select a physical iPhone device that supports UWB
- Press Cmd+R to build and run
The application requires the following permissions:
- Local Network Access: For MultipeerConnectivity
- Nearby Interaction: For UWB ranging functionality
- Notification Permission: For chat invitation notifications (optional)
- Launch Application: Open the app on a UWB-supported iPhone
- Multi-device Testing: Also launch the app on another UWB-supported iPhone
- Automatic Discovery: Devices will automatically discover and connect
- View Ranging: Check real-time distance and direction in radar view and device list
/// UWB and multi-peer connection manager (Main ViewModel)
class NearbyInteractionManager: NSObject, ObservableObject {
@Published var nearbyDevices: [MCPeerID: NearbyDevice] = [:]
@Published var isNISessionInvalidated = false
@Published var isUnsupportedDevice = false
// Core methods
func start() // Start service
func stop() // Stop service
}/// MultipeerConnectivity service management
class MCService: NSObject, ObservableObject {
@Published var connectedPeers: Set<MCPeerID> = []
@Published var discoveredPeers: Set<MCPeerID> = []
// Support up to 8 simultaneous device connections
// Each device pair uses independent MCSession
}/// Nearby device data model
struct NearbyDevice: Identifiable, Equatable {
let id: MCPeerID
var displayName: String
var distance: Float? // Distance (meters)
var direction: simd_float3? // 3D direction vector
var lastUpdateTime: Date
}// Configure in DebugLogger.swift
#if DEBUG
print("\(timestamp) >>> \(message)")
#endif-
UWB Not Supported Error
- Ensure using iPhone 11 or newer model
- Check iOS version is 15.0 or later
-
Devices Cannot Be Discovered
- Ensure both devices are on the same Wi-Fi network
- Check local network permission settings
- Restart the application
-
Inaccurate Ranging
- Ensure no metal objects blocking between devices
- Keep devices within 10 meters
- Avoid electromagnetic interference environments
- Create new files in appropriate directories
- Follow existing architectural patterns
- Use
@Publishedproperties to support SwiftUI binding - Add appropriate error handling and logging
// Planned features
- Chat invitation sending/receiving
- Real-time message transmission
- Chatroom management
- Local notification integration- Background Mode Limitations: UWB functionality pauses when app enters background
- Battery Consumption: Continuous UWB usage increases battery consumption
- Distance Limitations: Effective ranging distance approximately 10 meters
- Environmental Impact: Metal surfaces may affect ranging accuracy
- β Basic UWB ranging functionality
- β Multi-device connection support
- β Interactive radar view
- β Real-time distance and direction display
- π Chatroom functionality (In development)
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details
Saxon - December 4, 2024
Note: This application requires physical iPhone devices for testing; simulators do not support UWB functionality.