Skip to content

SArthurX/vector-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Vector Chat - UWB Proximity Interaction App

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.

🌐 Multi-language Support

This documentation is available in multiple languages:

View all available translations: Translation Index

🌟 Features

Core Functionality

  • 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

Visual Interface

  • 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

Advanced Features (In Development)

  • 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

πŸ“± System Requirements

Hardware Requirements

  • iPhone 11 or newer models (equipped with U1 chip)
  • iOS 15.0 or later

Compatible Devices

  • 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.

πŸ—οΈ Technical Architecture

Core Technology Stack

- SwiftUI: Modern UI framework
- NearbyInteraction: Apple's UWB ranging framework
- MultipeerConnectivity: Inter-device network connections
- Combine: Reactive programming
- UserNotifications: Local notification support

Architecture Design

Device 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

πŸ“ Project Structure

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

πŸš€ Quick Start

Installation Steps

  1. Clone the Project

    git clone https://github.com/SArthurX/vector-chat
    cd vector-chat
  2. Open Xcode Project

    open vector-chat.xcodeproj
  3. Configure Developer Certificate

    • Select your development team in Xcode
    • Ensure proper Bundle Identifier is set
  4. Build and Run

    • Select a physical iPhone device that supports UWB
    • Press Cmd+R to build and run

Permission Setup

The application requires the following permissions:

  • Local Network Access: For MultipeerConnectivity
  • Nearby Interaction: For UWB ranging functionality
  • Notification Permission: For chat invitation notifications (optional)

Usage Instructions

  1. Launch Application: Open the app on a UWB-supported iPhone
  2. Multi-device Testing: Also launch the app on another UWB-supported iPhone
  3. Automatic Discovery: Devices will automatically discover and connect
  4. View Ranging: Check real-time distance and direction in radar view and device list

πŸ”§ Development Guide

Main Component Overview

NearbyInteractionManager

/// 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
}

MCService

/// 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
}

NearbyDevice

/// 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
}

Debugging and Testing

Enable Debug Logging

// Configure in DebugLogger.swift
#if DEBUG
    print("\(timestamp) >>> \(message)")
#endif

Common Troubleshooting

  1. UWB Not Supported Error

    • Ensure using iPhone 11 or newer model
    • Check iOS version is 15.0 or later
  2. Devices Cannot Be Discovered

    • Ensure both devices are on the same Wi-Fi network
    • Check local network permission settings
    • Restart the application
  3. Inaccurate Ranging

    • Ensure no metal objects blocking between devices
    • Keep devices within 10 meters
    • Avoid electromagnetic interference environments

Extension Development

Adding New Features

  1. Create new files in appropriate directories
  2. Follow existing architectural patterns
  3. Use @Published properties to support SwiftUI binding
  4. Add appropriate error handling and logging

Chat Feature Development (In Progress)

// Planned features
- Chat invitation sending/receiving
- Real-time message transmission
- Chatroom management
- Local notification integration

πŸ“š Related Resources

Apple Official Documentation

Technical References

πŸ› Known Issues

  1. Background Mode Limitations: UWB functionality pauses when app enters background
  2. Battery Consumption: Continuous UWB usage increases battery consumption
  3. Distance Limitations: Effective ranging distance approximately 10 meters
  4. Environmental Impact: Metal surfaces may affect ranging accuracy

πŸ”„ Version History

v1.0.0 (Current Version)

  • βœ… Basic UWB ranging functionality
  • βœ… Multi-device connection support
  • βœ… Interactive radar view
  • βœ… Real-time distance and direction display
  • πŸ”„ Chatroom functionality (In development)

🀝 Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Create a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details

πŸ‘¨β€πŸ’» Author

Saxon - December 4, 2024


Note: This application requires physical iPhone devices for testing; simulators do not support UWB functionality.

About

An iOS application based on Apple's Ultra Wideband

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages