An iOS application that provides visual navigation for indoor environments using ARKit, designed to work in situations where GPS signals are weak or unavailable.
ARNavigation is a SwiftUI-based application that leverages Apple's ARKit framework to create an indoor navigation system. Users can create custom navigation paths by recording waypoints in 3D space, then use augmented reality to follow these paths for precise indoor navigation.
- Record custom navigation paths by walking through indoor spaces
- Store multiple paths with descriptions and timestamps
- Visual path preview with captured images
- Core Data persistence for reliable path storage
- Real-time augmented reality navigation using ARKit
- 3D waypoint visualization with directional indicators
- Compass-based orientation alignment
- Distance and direction feedback
- Audio cues for waypoint arrival
- SwiftUI-based modern interface
- Onboarding flow for new users
- Path management with edit/delete capabilities
- Visual alignment system for accurate navigation start
- ARWorldTrackingConfiguration: Provides 6DOF tracking for precise positioning
- RealityKit: Renders 3D waypoint models in AR space
- AnchorEntity: Anchors virtual content to real-world positions
- Camera Transform: Tracks user position and orientation
- Persistent storage for navigation paths
- Custom
Pathentity with properties:position: Array of 3D coordinates for waypointstruenorth: Compass headings for orientationdirection: Model names for waypoint visualizationpathname,pathdescription,timestamp: Metadata
CLLocationManager: Provides compass heading for orientation- True north calculation for accurate directional guidance
- SwiftUI: Modern declarative UI framework
- AVKit: Audio feedback system
- AudioToolbox: System sound notifications
ARNavigationApp (Main)
├── OnboardingView (First-time user experience)
└── ContentView (Main path management)
├── PathDetailView (Individual path details)
├── compareView (Path alignment interface)
└── ARViewContainer (AR navigation view)
- Real-time position tracking using ARKit
- Automatic waypoint recording based on movement
- Compass heading capture for each waypoint
- Core Data persistence
- Visual alignment between recorded and current view
- Camera feed comparison for accurate starting position
- Integration with
FrameModelfor camera management
- 3D model rendering for waypoints
- Real-time distance calculation
- Directional guidance using compass data
- Progress tracking and arrival detection
- iOS 14.0+ (ARKit requirement)
- Device with A12 Bionic chip or later (for optimal AR performance)
- Camera and location permissions
- Xcode 14.0+
- Swift 5.7+
- iOS Deployment Target: 14.0+
- ARKit (system framework)
- RealityKit (system framework)
- Core Data (system framework)
- Core Location (system framework)
- Tap the "+" button to create a new path
- Enter a name and description for your path
- Start recording at your desired starting point
- Walk to your destination while the app records waypoints
- End recording to save the path
- Select a saved path from the main list
- Position yourself at the starting point
- Align your orientation using the visual comparison screen
- Tap "开始导航" (Start Navigation) to begin AR guidance
- Follow the 3D waypoint indicators to your destination
Current Implementation:
DispatchQueue.main.async {
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) { _ in
// Navigation logic
}
}Recommended Modern Approach:
@MainActor
class NavigationManager: ObservableObject {
private var navigationTask: Task<Void, Never>?
func startNavigation() {
navigationTask = Task {
while !Task.isCancelled {
await updateNavigationState()
try? await Task.sleep(for: .milliseconds(100))
}
}
}
func stopNavigation() {
navigationTask?.cancel()
}
}Current: Basic ARWorldTrackingConfiguration
Upgrade to:
ARKit 6.0features including improved plane detectionRoomPlanframework integration for better indoor mapping- Enhanced tracking capabilities with scene understanding
Replace UIViewRepresentable with native SwiftUI:
// Modern SwiftUI approach with RealityView (iOS 17+)
import RealityKit
struct ARNavigationView: View {
var body: some View {
RealityView { content in
// Setup AR content
} update: { content in
// Update logic
}
.gesture(navigationGesture)
}
}Current: Traditional Core Data with manual management Recommend: SwiftData (iOS 17+) for modern persistence:
import SwiftData
@Model
class NavigationPath {
var name: String
var waypoints: [Waypoint]
var createdAt: Date
var description: String
init(name: String, description: String = "") {
self.name = name
self.description = description
self.waypoints = []
self.createdAt = Date()
}
}
@Model
class Waypoint {
var position: SIMD3<Float>
var heading: Double
var modelName: String
init(position: SIMD3<Float>, heading: Double, modelName: String) {
self.position = position
self.heading = heading
self.modelName = modelName
}
}Replace @StateObject/@ObservableObject with @Observable:
@Observable
class NavigationState {
var currentIndex: Int = 0
var distanceToNext: Float = 0
var isNavigating: Bool = false
var hasArrived: Bool = false
}Implement structured error handling:
enum NavigationError: LocalizedError {
case arNotAvailable
case pathNotFound
case trackingLost
var errorDescription: String? {
switch self {
case .arNotAvailable:
return "ARKit is not available on this device"
case .pathNotFound:
return "Navigation path could not be loaded"
case .trackingLost:
return "AR tracking has been lost"
}
}
}Implement efficient model loading:
@MainActor
class ModelCache: ObservableObject {
private var loadedModels: [String: ModelEntity] = [:]
func loadModel(named name: String) async -> ModelEntity? {
if let cached = loadedModels[name] {
return cached.clone(recursive: true)
}
do {
let model = try await ModelEntity.load(named: name)
loadedModels[name] = model
return model.clone(recursive: true)
} catch {
print("Failed to load model: \(error)")
return nil
}
}
}- iPhone 12 or later for optimal ARKit performance
- iPad Pro with LiDAR scanner for enhanced depth sensing
- Sufficient lighting conditions for camera-based tracking
The app requires:
- Camera access for AR functionality
- Location services for compass data
- Local storage for path data (no external data transmission)
- Integration with Core ML for object recognition and automated waypoint placement
- SharePlay support for collaborative path creation
- Accessibility improvements with VoiceOver integration
- Cloud sync with CloudKit for cross-device path sharing
- Apple Watch companion app for haptic navigation feedback
This project demonstrates modern iOS development practices combining ARKit, SwiftUI, and Core Data for indoor navigation solutions. The codebase provides a solid foundation for AR-based navigation applications and can be extended for various indoor positioning use cases.
[Add your license information here]
Last updated: March 2023 Compatible with: iOS 14.0+, Xcode 14.0+