Skip to content

Commit 5e8c82d

Browse files
benjohndeAlexander Manzer
and
Alexander Manzer
authored
iOS Wrapper improvements (zxing-cpp#630)
* refactor(wrappers/ios): enable adding ios dependency in a clean way - move `Package.swift` to root - get rid of `unsafeFlags` - adjust readme and gitignore files * feat(wrappers/ios/demo): adapt xcodeproj for streamlined deps usage - add `ZXingCppWrapper` as swift package dependency - embed `ZXingCppWrapper` framework in project - lower minimum deployment target to `iOS 13.0` - start stream on background thread - add more camera variants to enable macro mode on newer devices * refactor(core): remove apple framework references from cmake file * fix(wrappers/ios): change c++ language standard to 20 * chore(workflows/ci): replace old script invocation with swift pm build command * fix(wrappers/ios): omit the type (static vs dynamic) for the library in swift pm Co-authored-by: Alexander Manzer <[email protected]>
1 parent a7fb90c commit 5e8c82d

16 files changed

+68
-114
lines changed

.github/workflows/ci.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,10 @@ jobs:
8080
with:
8181
ref: ${{github.ref}}
8282

83-
- name: Build the ZXingCpp.xcframework
83+
- name: Build the swift package
8484
shell: sh
85-
working-directory: ${{runner.workspace}}/${{github.event.repository.name}}/wrappers/ios
86-
run: ./build-release.sh
87-
88-
- name: Upload .xcframework
89-
uses: actions/upload-artifact@v3
90-
with:
91-
name: ios-artifacts
92-
path: ${{runner.workspace}}/${{github.event.repository.name}}/wrappers/ios/ZXingCpp.xcframework
85+
working-directory: ${{runner.workspace}}/${{github.event.repository.name}}
86+
run: swift build
9387

9488
- name: Build the demo app
9589
shell: sh

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ CMakeLists.txt.user
55
*.d
66
*.a
77
compile_commands.json
8+
.swiftpm
9+
.build
+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version:5.3
1+
// swift-tools-version:5.7.1
22
import PackageDescription
33

44
let package = Package(
@@ -9,23 +9,25 @@ let package = Package(
99
products: [
1010
.library(
1111
name: "ZXingCppWrapper",
12-
type: .static,
1312
targets: ["ZXingCppWrapper"])
1413
],
1514
targets: [
16-
.binaryTarget(
15+
.target(
1716
name: "ZXingCpp",
18-
path: "ZXingCpp.xcframework"
17+
path: "core/src",
18+
publicHeadersPath: "."
1919
),
2020
.target(
2121
name: "ZXingCppWrapper",
2222
dependencies: ["ZXingCpp"],
23-
path: "Sources/Wrapper",
23+
path: "wrappers/ios/Sources/Wrapper",
2424
publicHeadersPath: ".",
25-
cxxSettings: [
26-
.unsafeFlags(["-stdlib=libc++"]),
27-
.unsafeFlags(["-std=gnu++17"])
25+
linkerSettings: [
26+
.linkedFramework("CoreGraphics"),
27+
.linkedFramework("CoreImage"),
28+
.linkedFramework("CoreVideo")
2829
]
2930
)
30-
]
31+
],
32+
cxxLanguageStandard: CXXLanguageStandard.gnucxx20
3133
)

core/CMakeLists.txt

-19
Original file line numberDiff line numberDiff line change
@@ -482,25 +482,6 @@ endif()
482482

483483
set_target_properties(ZXing PROPERTIES PUBLIC_HEADER "${PUBLIC_HEADERS}")
484484

485-
if (APPLE AND BUILD_APPLE_FRAMEWORK)
486-
set_target_properties(ZXing PROPERTIES
487-
FRAMEWORK TRUE
488-
FRAMEWORK_VERSION "C"
489-
XCODE_ATTRIBUTE_DEFINES_MODULE YES
490-
XCODE_ATTRIBUTE_BUILD_LIBRARY_FOR_DISTRIBUTION YES
491-
XCODE_ATTRIBUTE_MODULEMAP_FILE "wrappers/ios/Sources/Wrapper/module.modulemap"
492-
XCODE_ATTRIBUTE_CLANG_ENABLE_OBJC_ARC YES
493-
MACOSX_FRAMEWORK_IDENTIFIER "com.zxing-cpp.ios"
494-
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PROJECT_VERSION}
495-
MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
496-
CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH NO
497-
#MACOSX_FRAMEWORK_INFO_PLIST Info.plist
498-
PUBLIC_HEADER "${PUBLIC_HEADERS}"
499-
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
500-
XCODE_ATTRIBUTE_ENABLE_BITCODE "NO"
501-
)
502-
endif()
503-
504485
include (GNUInstallDirs)
505486

506487
set(ZX_INSTALL_TARGETS ZXing)

wrappers/ios/.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
.swiftpm
2-
_builds
3-
.build
41
xcuserdata
5-
ZXingCpp.xcframework

wrappers/ios/Info.plist

-723 Bytes
Binary file not shown.

wrappers/ios/README.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
11
# ZXingCpp iOS Framework
22

3-
To use the iOS (wrapper) framework in other apps, it is easiest
4-
to build the library project and include the resulting xcframework
5-
file in your app.
6-
7-
## How to build and use
8-
9-
To build the xcframework:
10-
11-
$ ./build-release.sh
12-
13-
Then you can add the iOS Wrapper as a local Swift Package by adding it as a dependency to your app.
14-
Don't forget to add the wrapper to the `Frameworks, Libraries, and Embedded Content` section within the `General` tab.
3+
Add the iOS wrapper either as a local Swift Package by adding it as a dependency to your app or add the repository, the Package.swift file is automatically picked.

wrappers/ios/Sources/Wrapper/Reader/ZXIBarcodeReader.mm

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#import "ZXIBarcodeReader.h"
6-
#import "ZXing/ReadBarcode.h"
7-
#import "ZXing/ImageView.h"
8-
#import "ZXing/Result.h"
6+
#import "ReadBarcode.h"
7+
#import "ImageView.h"
8+
#import "Result.h"
99
#import "ZXIFormatHelper.h"
1010
#import "ZXIPosition+Helper.h"
1111

wrappers/ios/Sources/Wrapper/Reader/ZXIDecodeHints.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#import "ZXIDecodeHints.h"
6-
#import "ZXing/DecodeHints.h"
6+
#import "DecodeHints.h"
77

88
@interface ZXIDecodeHints()
99
@property(nonatomic) ZXing::DecodeHints zxingHints;

wrappers/ios/Sources/Wrapper/Reader/ZXIPosition+Helper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#import <Foundation/Foundation.h>
66
#import "ZXIPosition.h"
7-
#import "ZXing/Result.h"
7+
#import "Result.h"
88

99
NS_ASSUME_NONNULL_BEGIN
1010

wrappers/ios/Sources/Wrapper/Writer/ZXIBarcodeWriter.mm

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#import <CoreGraphics/CoreGraphics.h>
66
#import "ZXIBarcodeWriter.h"
7-
#import "ZXing/MultiFormatWriter.h"
8-
#import "ZXing/BitMatrix.h"
7+
#import "MultiFormatWriter.h"
8+
#import "BitMatrix.h"
99
#import "ZXIFormatHelper.h"
1010
#import "ZXIErrors.h"
1111
#import <iostream>

wrappers/ios/Sources/Wrapper/ZXIFormatHelper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
#import <Foundation/Foundation.h>
6-
#import "ZXing/BarcodeFormat.h"
6+
#import "BarcodeFormat.h"
77
#import "ZXIFormat.h"
88

99
NS_ASSUME_NONNULL_BEGIN

wrappers/ios/build-release.sh

-37
This file was deleted.

wrappers/ios/demo/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
# ZXingWrapper Demo Project
22

33
This demo-project sets up a basic `AVCaptureSession` and uses ZXing on the incoming frames.
4-
You have to build the `ZXing.xcframework` before, by performing the `build-release.sh` script
5-
in the parent-directory.

wrappers/ios/demo/demo.xcodeproj/project.pbxproj

+32-10
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@
1313
388BF030283CC49D005CE271 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 388BF02E283CC49D005CE271 /* Main.storyboard */; };
1414
388BF032283CC49E005CE271 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 388BF031283CC49E005CE271 /* Assets.xcassets */; };
1515
388BF035283CC49E005CE271 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 388BF033283CC49E005CE271 /* LaunchScreen.storyboard */; };
16-
9507445028609C0500E02D06 /* ZXingCppWrapper in Frameworks */ = {isa = PBXBuildFile; productRef = 9507444F28609C0500E02D06 /* ZXingCppWrapper */; };
16+
5EFA4B742ADF0F35000132A0 /* ZXingCppWrapper in Frameworks */ = {isa = PBXBuildFile; productRef = 5EFA4B732ADF0F35000132A0 /* ZXingCppWrapper */; };
1717
950744522860A3A300E02D06 /* WriteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 950744512860A3A300E02D06 /* WriteViewController.swift */; };
1818
/* End PBXBuildFile section */
1919

20+
/* Begin PBXCopyFilesBuildPhase section */
21+
52A975482ADAD7DE002D6BD8 /* Embed Frameworks */ = {
22+
isa = PBXCopyFilesBuildPhase;
23+
buildActionMask = 2147483647;
24+
dstPath = "";
25+
dstSubfolderSpec = 10;
26+
files = (
27+
);
28+
name = "Embed Frameworks";
29+
runOnlyForDeploymentPostprocessing = 0;
30+
};
31+
/* End PBXCopyFilesBuildPhase section */
32+
2033
/* Begin PBXFileReference section */
2134
388BF025283CC49D005CE271 /* demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = demo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2235
388BF028283CC49D005CE271 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -27,16 +40,16 @@
2740
388BF034283CC49E005CE271 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2841
388BF036283CC49E005CE271 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2942
388BF043283CE0AC005CE271 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
43+
5EFA4B712ADF0F16000132A0 /* zxing-cpp */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = "zxing-cpp"; path = ../../..; sourceTree = "<group>"; };
3044
950744512860A3A300E02D06 /* WriteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WriteViewController.swift; sourceTree = "<group>"; };
31-
9550105328609B7900ED103F /* ios */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = ios; path = ..; sourceTree = "<group>"; };
3245
/* End PBXFileReference section */
3346

3447
/* Begin PBXFrameworksBuildPhase section */
3548
388BF022283CC49D005CE271 /* Frameworks */ = {
3649
isa = PBXFrameworksBuildPhase;
3750
buildActionMask = 2147483647;
3851
files = (
39-
9507445028609C0500E02D06 /* ZXingCppWrapper in Frameworks */,
52+
5EFA4B742ADF0F35000132A0 /* ZXingCppWrapper in Frameworks */,
4053
);
4154
runOnlyForDeploymentPostprocessing = 0;
4255
};
@@ -46,11 +59,11 @@
4659
388BF01C283CC49D005CE271 = {
4760
isa = PBXGroup;
4861
children = (
62+
5EFA4B702ADF0F16000132A0 /* Packages */,
4963
388BF043283CE0AC005CE271 /* README.md */,
50-
388BF03E283CD6C5005CE271 /* Packages */,
5164
388BF027283CC49D005CE271 /* demo */,
5265
388BF026283CC49D005CE271 /* Products */,
53-
388BF040283CD908005CE271 /* Frameworks */,
66+
5EFA4B722ADF0F35000132A0 /* Frameworks */,
5467
);
5568
sourceTree = "<group>";
5669
};
@@ -77,15 +90,15 @@
7790
path = demo;
7891
sourceTree = "<group>";
7992
};
80-
388BF03E283CD6C5005CE271 /* Packages */ = {
93+
5EFA4B702ADF0F16000132A0 /* Packages */ = {
8194
isa = PBXGroup;
8295
children = (
83-
9550105328609B7900ED103F /* ios */,
96+
5EFA4B712ADF0F16000132A0 /* zxing-cpp */,
8497
);
8598
name = Packages;
8699
sourceTree = "<group>";
87100
};
88-
388BF040283CD908005CE271 /* Frameworks */ = {
101+
5EFA4B722ADF0F35000132A0 /* Frameworks */ = {
89102
isa = PBXGroup;
90103
children = (
91104
);
@@ -102,14 +115,15 @@
102115
388BF021283CC49D005CE271 /* Sources */,
103116
388BF022283CC49D005CE271 /* Frameworks */,
104117
388BF023283CC49D005CE271 /* Resources */,
118+
52A975482ADAD7DE002D6BD8 /* Embed Frameworks */,
105119
);
106120
buildRules = (
107121
);
108122
dependencies = (
109123
);
110124
name = demo;
111125
packageProductDependencies = (
112-
9507444F28609C0500E02D06 /* ZXingCppWrapper */,
126+
5EFA4B732ADF0F35000132A0 /* ZXingCppWrapper */,
113127
);
114128
productName = demo;
115129
productReference = 388BF025283CC49D005CE271 /* demo.app */;
@@ -139,6 +153,8 @@
139153
Base,
140154
);
141155
mainGroup = 388BF01C283CC49D005CE271;
156+
packageReferences = (
157+
);
142158
productRefGroup = 388BF026283CC49D005CE271 /* Products */;
143159
projectDirPath = "";
144160
projectRoot = "";
@@ -314,6 +330,7 @@
314330
buildSettings = {
315331
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
316332
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
333+
CODE_SIGN_IDENTITY = "Apple Development";
317334
CODE_SIGN_STYLE = Automatic;
318335
CURRENT_PROJECT_VERSION = 1;
319336
DEVELOPMENT_TEAM = "";
@@ -326,13 +343,15 @@
326343
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
327344
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
328345
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
346+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
329347
LD_RUNPATH_SEARCH_PATHS = (
330348
"$(inherited)",
331349
"@executable_path/Frameworks",
332350
);
333351
MARKETING_VERSION = 1.0;
334352
PRODUCT_BUNDLE_IDENTIFIER = "com.zxing-cpp.ios.demo-${SAMPLE_CODE_DISAMBIGUATOR}";
335353
PRODUCT_NAME = "$(TARGET_NAME)";
354+
PROVISIONING_PROFILE_SPECIFIER = "";
336355
SAMPLE_CODE_DISAMBIGUATOR = "${DEVELOPMENT_TEAM}";
337356
SWIFT_EMIT_LOC_STRINGS = YES;
338357
SWIFT_VERSION = 5.0;
@@ -345,6 +364,7 @@
345364
buildSettings = {
346365
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
347366
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
367+
CODE_SIGN_IDENTITY = "Apple Development";
348368
CODE_SIGN_STYLE = Automatic;
349369
CURRENT_PROJECT_VERSION = 1;
350370
DEVELOPMENT_TEAM = "";
@@ -357,13 +377,15 @@
357377
INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait;
358378
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
359379
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
380+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
360381
LD_RUNPATH_SEARCH_PATHS = (
361382
"$(inherited)",
362383
"@executable_path/Frameworks",
363384
);
364385
MARKETING_VERSION = 1.0;
365386
PRODUCT_BUNDLE_IDENTIFIER = "com.zxing-cpp.ios.demo-${SAMPLE_CODE_DISAMBIGUATOR}";
366387
PRODUCT_NAME = "$(TARGET_NAME)";
388+
PROVISIONING_PROFILE_SPECIFIER = "";
367389
SAMPLE_CODE_DISAMBIGUATOR = "${DEVELOPMENT_TEAM}";
368390
SWIFT_EMIT_LOC_STRINGS = YES;
369391
SWIFT_VERSION = 5.0;
@@ -395,7 +417,7 @@
395417
/* End XCConfigurationList section */
396418

397419
/* Begin XCSwiftPackageProductDependency section */
398-
9507444F28609C0500E02D06 /* ZXingCppWrapper */ = {
420+
5EFA4B732ADF0F35000132A0 /* ZXingCppWrapper */ = {
399421
isa = XCSwiftPackageProductDependency;
400422
productName = ZXingCppWrapper;
401423
};

0 commit comments

Comments
 (0)