Advanced scanning capabilities with QR code detection and credit card text recognition
This module provides two powerful scanning capabilities:
- π QR Code Scanner - Real-time QR code detection with beautiful UI
- π³ Credit Card Scanner - Advanced text recognition for credit card data extraction
Both modules are built with SwiftUI and integrate seamlessly with your app's navigation and UI.
- AVFoundation - Camera and video processing
- Vision Framework - Advanced text recognition (Card Scanner)
- SwiftUI - Modern UI framework
- Combine - Reactive programming
- Real-time Processing - 60fps detection
- Memory Efficient - Optimized buffer handling
- Battery Optimized - Efficient camera usage
- Region of Interest - Focused scanning areas
- Camera Permission Denied - Clear permission request
- Scanning Area Not Set - Proper initialization checks
- Session Configuration - Robust session setup
- Text Recognition Errors - Robust error recovery (Card Scanner)
- Real-time QR Code Detection - Instant scanning with live feedback
- Dynamic Scanning Area - Adaptive scanning frame that responds to QR code position
- Camera Permission Handling - Graceful permission requests and error handling
- Flashlight Integration - Built-in flashlight control for low-light scanning
- Smooth Animations - Beautiful spring animations for UI transitions
- Error Recovery - Comprehensive error handling with user-friendly messages
- Navigation Integration - Seamless integration with app navigation
QRCodeScanner/
βββ Model/
β βββ QRCodeData.swift # QR code position and size data
βββ View/
β βββ QRScannerView.swift # Main scanning interface
β βββ QRScreen.swift # Screen container
β βββ ScanningOverlayView.swift # Scanning overlay UI
β βββ CameraPreview.swift # Camera preview component
βββ ViewModel/
βββ QRScannerViewModel.swift # Main view model with AVFoundation
βββ QRCodeProcessor.swift # QR code processing logic
The main scanning interface that provides:
- Camera preview with real-time QR detection
- Dynamic scanning overlay with rounded corners
- Flashlight button integration
- Permission status handling
- Error state management
Handles all the scanning logic:
- AVFoundation Integration - Camera session management
- Real-time Processing - Live QR code detection
- Permission Management - Camera access handling
- Error Handling - Comprehensive error states
- Navigation Control - Seamless app navigation
Specialized processor for QR code detection:
- Metadata Output - AVCaptureMetadataOutput configuration
- Position Tracking - Real-time QR code position updates
- Size Detection - Dynamic QR code size calculation
- Real-time Text Recognition - Live credit card data extraction using Vision framework
- Multi-field Detection - Simultaneous detection of card number, expiry date, and holder name
- Smart Data Processing - Intelligent text processing with regular expressions
- Camera Orientation Support - Automatic handling of portrait and landscape modes
- Flashlight Integration - Built-in flashlight control for optimal scanning
- Confirmation Timer - Smart detection confirmation to avoid false positives
- Error Recovery - Robust error handling and recovery mechanisms
- Beautiful UI - Modern card-shaped overlay with smooth animations
CardScanner/
βββ Model/
β βββ CreditCard.swift # Credit card data model
β βββ CardRegularExpressions.swift # Regex patterns for validation
β βββ ScannerState.swift # Scanning state management
β βββ Candidate.swift # Text recognition candidates
β βββ TextRequest.swift # Vision text recognition config
βββ View/
β βββ CardScannerView.swift # Main scanning interface
β βββ CreditCardScannerView.swift # Core camera integration
β βββ CardScreen.swift # Screen container
β βββ CardOverlayView.swift # Card-shaped overlay
β βββ CornerShape.swift # Custom corner shapes
β βββ ScannedCardData.swift # Scanned data display
βββ ViewModel/
β βββ CreditCardScannerViewModel.swift # Main view model
βββ Service/
βββ CreditCardDataProcessor.swift # Text processing service
βββ CameraStateManager.swift # Camera state management
The main scanning interface featuring:
- Card-shaped Overlay - Visual guide for card positioning
- Real-time Preview - Live camera feed with text recognition
- Flashlight Control - Built-in flashlight toggle
- Camera Flip - Front/back camera switching
- Orientation Support - Automatic portrait/landscape handling
Advanced view model with Vision framework integration:
- Vision Text Recognition - Real-time text detection
- Multi-field Processing - Simultaneous card number, expiry, and name detection
- Confirmation Logic - Smart detection confirmation with timers
- Data Validation - Regex-based field validation
- State Management - Comprehensive scanning state handling
Specialized service for text processing:
- Regex Validation - Credit card number and date validation
- Text Cleaning - Noise removal and text normalization
- Field Mapping - Intelligent field identification
- Confidence Scoring - Detection confidence assessment
- Dynamic Frame - Adapts to QR code position and size
- Rounded Corners - Modern, clean design
- Smooth Animations - Spring-based transitions
- Visual Feedback - Clear scanning area indication
- Card-shaped Cutout - Visual guide matching credit card dimensions
- Rounded Corners - Modern, clean design aesthetic
- Dynamic Sizing - Adapts to different card sizes
- Visual Feedback - Clear scanning area indication
- Real-time Preview - Live camera feed
- Permission Handling - Graceful permission requests
- Error States - User-friendly error messages
- Flashlight Control - Built-in flashlight toggle
Both modules automatically handle camera permissions:
- Request Access - Prompts user for camera permission
- Status Monitoring - Tracks permission status
- Error Handling - Provides clear error messages
- Settings Integration - Direct link to device settings
- Always check permissions before starting the scanner
- Handle navigation properly to avoid memory leaks
- Provide user feedback for scanning states
- Test on different devices for compatibility
- Consider lighting conditions for optimal scanning
- Test on Real Cards - Use actual credit cards for testing
- Lighting Conditions - Ensure adequate lighting for optimal scanning
- Card Positioning - Guide users to position cards properly
- Privacy Compliance - Handle sensitive data securely
- Error Recovery - Provide clear error messages and recovery options
isQRCodeVisible
- QR code detection statusqrCodePosition
- Current QR code positionqrCodeSize
- QR code dimensionspermissionStatus
- Camera permission stateerror
- Current error state
selectedCard
- Current scanned card datascannerState
- Current scanning statecameraOrientation
- Current camera orientationdetectionConfidence
- Text recognition confidence
- No Data Storage - Scanned data is not persisted
- Memory Cleanup - Automatic buffer cleanup
- Permission Handling - Secure camera access
- No Data Storage - Scanned data is not persisted
- Memory Cleanup - Automatic buffer cleanup
- Permission Handling - Secure camera access
- Data Validation - Input sanitization and validation
- Import the module in your SwiftUI view
- Create a ViewModel with AVCaptureSession
- Set up navigation with NavigationPathManager
- Handle QR code results in your callback
- Test permissions on real devices
- Import the module in your SwiftUI view
- Set up camera permissions in Info.plist
- Create a data processor for text recognition
- Handle scanned data in your callback
- Test with real cards for optimal results
Built with using SwiftUI, AVFoundation, and Vision framework