การสแกนบาร์โค้ดบน iOS และ Android: การพัฒนาแบบเนทีฟ
Native mobile barcode scanning — AVFoundation on iOS, CameraX on Android, real-time overlay rendering, and multi-code scanning.
Barcode Scanning in Native Mobile Apps
Mobile devices have become ubiquitous barcode scanners, with built-in cameras and processing power sufficient to decode any barcode symbology. This guide covers implementing barcode scanning in iOS and Android native applications.
iOS: Vision Framework
Apple's Vision framework provides built-in barcode detection:
Supported symbologies include EAN-13, EAN-8, UPC-A, UPC-E, Code 128, Code 39, ITF-14, Data Matrix, QR Code, PDF417, and Aztec Code.
Key capabilities: - Real-time detection from camera feed - Multiple barcode detection in a single frame - Bounding box coordinates for UI overlay - Symbology identification in the result
Android: ML Kit Barcode Scanning
Google's ML Kit provides barcode scanning for Android:
Supports all major 1D and 2D symbologies. Key features: - On-device processing (no network required) - Real-time scanning from CameraX - Structured data extraction (URLs, contact info, Wi-Fi credentials from QR codes) - Multi-barcode detection
Cross-Platform Options
- React Native: react-native-camera with barcode detection, or react-native-vision-camera with frame processor plugins
- Flutter: mobile_scanner or google_mlkit_barcode_scanning packages
- Xamarin: ZXing.Net.Mobile wrapper
Camera Configuration
For reliable barcode scanning, configure the camera appropriately:
- Resolution: 1080p minimum, 4K for small or dense barcodes
- Autofocus: Continuous autofocus mode (not single-shot)
- Exposure: Auto-exposure with bias toward faster shutter speeds
- Frame rate: 30fps for responsive scanning
- Region of interest: Limit detection to a centered rectangle for better performance
Scan Performance Optimization
- Throttle processing: Process every 3rd or 5th frame rather than every frame to reduce CPU/battery usage
- Region of interest: Crop the camera frame to the expected barcode area before processing
- Symbology filtering: Only enable detection for the symbologies you expect (reduces false positives and speeds processing)
- Haptic feedback: Provide vibration feedback on successful scan for immediate user confirmation
Handling GS1 Data
When scanning GS1-128 or gs1-datamatrix-term/" class="glossary-term-link" data-term="GS1 DataMatrix" data-definition="Data Matrix with GS1 AIs for pharma and food traceability." data-category="2D & Matrix Symbologies">GS1 DataMatrix on mobile:
- The raw scan result contains FNC1 as GS (ASCII 29) characters
- Parse Application Identifiers to extract GTIN, batch, expiry, and serial
- Display parsed fields in a structured UI rather than the raw data string
- Validate check digits and AI formats before processing
Accessibility Considerations
- Provide audio feedback for successful scans (essential for visually impaired users)
- Support manual entry as a fallback when scanning fails
- Ensure sufficient contrast for the scanning viewfinder overlay
- Test with screen readers enabled to verify the scan result is announced
Enterprise Mobile Scanning
For enterprise applications, consider dedicated mobile computers (Zebra TC-series, Honeywell CT-series) that offer:
- Hardware scan buttons (faster than on-screen buttons)
- Extended-range scanning (up to 15 meters with specialized engines)
- Rugged construction for warehouse environments
- Built-in GS1 data parsing in the scan engine firmware