In the previous tutorial, we explored how to build a SwiftUI barcode scanner app for macOS using the Dynamsoft Capture Vision C++ SDK. Since SwiftUI is a cross-platform framework supporting both macOS and iOS, and the Dynamsoft Capture Vision SDK provides a Swift Package Manager (SPM) for iOS, it is theoretically possible to make the SwiftUI project compatible with both platforms. This article demonstrates how to modify the existing macOS barcode scanner project to support iOS.
iOS 1D/2D Barcode Scanner Demo Video
Prerequisites
: The Swift Package Manager (SPM) for the Dynamsoft Capture Vision SDK.
Configuring SwiftUI Barcode Scanner Project for macOS and iOS
In Xcode, select
File > Add Package Dependenciesto add thecapture-vision-spmpackage:
For macOS-specific bridging code that is unnecessary for iOS, ensure the build passes by conditionally excluding the macOS code using macros in
*.hand*.mmfiles:
CODE#include <TargetConditionals.h>
#if defined(__APPLE__) && defined(__MACH__) && !TARGET_OS_IPHONE
// macOS code
#endif
To access the camera on iOS, go to
Project > Infoand add theNSCameraUsageDescriptionkey:
Run the barcode scanner app to see the results:
↗ Original-Artikel auf dev.to lesenVollständiger Original-BerichtAusführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
SOCIAL SHARE CARD GENERATOR