Unable to integrate ZXingObjC in iOS Swift Project

Im working on an iOS project that shows the client number in a barcode. I installed the ZXingObjC framework with CocoaPods described in GitHub .

I can compile my project without errors. I can also use ZXingObjC classes in my Objective-C classes without errors. After that, I added the import command #import <ZXingObjC/ZXingObjC.h> to my bridge header file, like other custom Objective-C classes, without compilation errors. (I had a test header file, killing some import statements and getting the expected file exception not found.)

But now I can not use any ZXingObjC class in my fast classes. I got the following compilation error: Use of undeclared type '...' . Xcode autocomplete also does not work.

eg.

 var test : ZXMultiFormatWriter? >> Use of undeclared type 'ZXMultiFormatWriter' 

I tried:

  • set up a new project, the same release
  • checked header search path: $(SRCROOT)/Pods/Headers/Public/Adjust
  • reinstalled the ZXingObjC infrastructure
  • assembly settings checked: Enable Modules: YES
  • proven assembly parameters: Other Linker Flags: $(inherited) -ObjC -framework "ZXingObjC"
  • linked binaries checked at build stages: structure added
  • checked the import operation in the bridge header file ( #import <ZXingObjC/ZXingObjC.h> and #import "ZXingObjC/ZXingObjC.h" - no difference)
  • Windows style: restarting Xcode and Mac; -)

I use:

  • Xcode: 6.3.2
  • CocoaPods: 0.37.2
  • Project deployment goal: iOS 8.0
  • SDK: 8.3

Does anyone know a problem? Can anyone help? How can I make the ZXingObjC structure available in swift?

+5
source share
4 answers

This is actually not an easy problem:

Podfile

 source 'https://github.com/CocoaPods/Specs.git' platform :ios, '8.0' use_frameworks! pod 'ZXingObjC', '~> 3.1' 

So on the terminal:

 cd workspace pod install 

Then, after opening the project on Xcode, you should edit the bridge title by adding ZXingObj:

 #import <ZXingObjC/ZXingObjC.h> 

Finally, in your fast classes that use ZXingObjC, you need to import ZXingObjC.

 import ZXingObjC class ZXingObjCWrapper { func encode() { let writer = ZXMultiFormatWriter.writer() .... } } 
+4
source

In my project, the header search path is incorrect. Valid Values:

 $(inherited) "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/ZXingObjC" 

The second and third lines were not added by the installation with CocoaPods.

EDIT: The installed infrastructure should be added to the Embedded Binary tab in the General tab of the project.

0
source

I tried everything on this page to add ZXingObjC as a Pod. My goal was to create an Aztec barcode.

I checked my header search path. As Reddas said, I had to manually add "$ {PODS_ROOT} / Headers / Public / ZXingObjC". I also added ZXingObjC as an embedded binary (on the General tab).

I checked my bridge file and everything was fine. I checked the controllers of my kind, where I wanted to create a barcode. ZXingObjC import was there.

No compilation errors. But I can not declare the variable ZXingObjC.

Bad luck. Any other suggestions?

EDIT . I went to Goals, Customize Options, and searched for Heading Search Paths. I added to BOTH "$ {PODS_ROOT} / Headers / General / ZXingObjC" and "$ {PODS_ROOT} / Headers / Private / ZXingObjC"

It all seemed to break. He is working now. Oddly enough, now I can delete these entries and work.

0
source

The rest of the code when you need to install UIImage with this barcode:

 func generateDataMatrixQRCode(from string: String) -> UIImage? { do { let writer = ZXMultiFormatWriter() let hints = ZXEncodeHints() as ZXEncodeHints let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints) if let imageRef = ZXImage.init(matrix: result) { if let image = imageRef.cgimage { return UIImage.init(cgImage: image) } } } catch { print(error) } return nil } 
0
source

All Articles