Skip to content

danilpapa/QRCardScanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“± Scanner Modules

Advanced scanning capabilities with QR code detection and credit card text recognition

πŸš€ Overview

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.

qrScanner

cardScanner


πŸ›  Technical Details

Dependencies

  • AVFoundation - Camera and video processing
  • Vision Framework - Advanced text recognition (Card Scanner)
  • SwiftUI - Modern UI framework
  • Combine - Reactive programming

Performance

  • Real-time Processing - 60fps detection
  • Memory Efficient - Optimized buffer handling
  • Battery Optimized - Efficient camera usage
  • Region of Interest - Focused scanning areas

Error Handling

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

πŸ” QR Code Scanner Module

Features

  • 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

Module Structure

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

Core Components

QRScannerView

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

QRScannerViewModel

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

QRCodeProcessor

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

πŸ’³ Credit Card Scanner Module

Features

  • 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

Module Structure

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

Core Components

CardScannerView

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

CreditCardScannerViewModel

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

CreditCardDataProcessor

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

🎨 UI Features

QR Scanner UI

  • 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 Scanner UI

  • 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

Camera Integration (Both Modules)

  • Real-time Preview - Live camera feed
  • Permission Handling - Graceful permission requests
  • Error States - User-friendly error messages
  • Flashlight Control - Built-in flashlight toggle

πŸ” Permissions

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

🎯 Best Practices

QR Scanner

  1. Always check permissions before starting the scanner
  2. Handle navigation properly to avoid memory leaks
  3. Provide user feedback for scanning states
  4. Test on different devices for compatibility
  5. Consider lighting conditions for optimal scanning

Card Scanner

  1. Test on Real Cards - Use actual credit cards for testing
  2. Lighting Conditions - Ensure adequate lighting for optimal scanning
  3. Card Positioning - Guide users to position cards properly
  4. Privacy Compliance - Handle sensitive data securely
  5. Error Recovery - Provide clear error messages and recovery options

πŸ”„ State Management

QR Scanner States

  • isQRCodeVisible - QR code detection status
  • qrCodePosition - Current QR code position
  • qrCodeSize - QR code dimensions
  • permissionStatus - Camera permission state
  • error - Current error state

Card Scanner States

  • selectedCard - Current scanned card data
  • scannerState - Current scanning state
  • cameraOrientation - Current camera orientation
  • detectionConfidence - Text recognition confidence

πŸ” Security Considerations

QR Scanner

  • No Data Storage - Scanned data is not persisted
  • Memory Cleanup - Automatic buffer cleanup
  • Permission Handling - Secure camera access

Card Scanner

  • No Data Storage - Scanned data is not persisted
  • Memory Cleanup - Automatic buffer cleanup
  • Permission Handling - Secure camera access
  • Data Validation - Input sanitization and validation

πŸš€ Getting Started

QR Scanner Setup

  1. Import the module in your SwiftUI view
  2. Create a ViewModel with AVCaptureSession
  3. Set up navigation with NavigationPathManager
  4. Handle QR code results in your callback
  5. Test permissions on real devices

Card Scanner Setup

  1. Import the module in your SwiftUI view
  2. Set up camera permissions in Info.plist
  3. Create a data processor for text recognition
  4. Handle scanned data in your callback
  5. Test with real cards for optimal results

Built with using SwiftUI, AVFoundation, and Vision framework

About

Sample module for scanning all types of qrCodes and credit cards

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages