This article reprinted to http://blog.csdn.net/louercab/article/details/26448587
Steps
First of all, use Xcode to create our demo, named Testzxing (whichever you like). Find the location of the project, open the folder, create a folder inside the name Zxing,
Then download the zxing from the https://github.com/zxing/zxing . Unzip to open. Since zxing supports multiple platforms, we only need to support iOS, so we just have to keep two folders (CPP and iphone), copy two folders, and put them under the Zxing folder created in the first step.
Then we deleted the unwanted documents. For things under the Cpp/core/src folder, we only keep the bigint and zxing two folders.
For the iphone folder, we need to remove the Iphone/zxingwidget directory below theTestsFolder. After deletion
Next Open our demo, add the zxing directory to our iOS project, then drag the zxingwidget.xcodeproj file below Iphone/zxingwidget to the zxing sibling directory. (If you find a tests folder, delete the tests folder)
Then click Build Phases tab in the Project panel, then add the Target Dependencies and Link binary, and increase these framework dependencies, add
Add two header search path to the settings, note that the first path is set to loop over the subtitle, and the second does not loop, as shown in:
In this step, we have integrated the Zxing library. Compile it at this time to see if it is an error. Unfortunately, it does give an error, and the type is:
At this point, we find the wrong line of code, double-click the code to the left of the red dot, will pop up as a hint:
Then double-click on the second line (the line with the blue bottom) and find the error magically disappears.
Join zxing dependencies in our class.
#import <ZXingWidgetController.h>
#import <QRCodeReader.h>
This is the interface we draw:
In. M we write this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
- (IBAction)zxingAction:(id)sender {
ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO];
NSMutableSet *readers = [[NSMutableSet alloc ] init];
QRCodeReader* qrcodeReader = [[QRCodeReader alloc] init];
[readers addObject:qrcodeReader];
[qrcodeReader release];
widController.readers = readers;
[readers release];
[self presentViewController:widController animated:YES completion:nil];
[widController release]; } - (
void
)zxingController:(ZXingWidgetController*)controller didScanResult:(NSString *)result {
self.showTextView.text = result;
[controller dismissViewControllerAnimated:YES completion:nil]; }
- (
void
)zxingControllerDidCancel:(ZXingWidgetController *)controller {
[controller dismissViewControllerAnimated:YES completion:nil]; }
|
This time compile, will report ' Iosstream ' File not found error, then we need to change the. m file to a. mm file, and call the. m file for this class instead. mm file. For more information, please refer to: http://stackoverflow.com/questions/8154024/iostream-file-not-found-in-xcode-4-2
After modification
Because I introduced the Ssviewcontroller in the header file.
#import <ZXingWidgetController.h>
#import <QRCodeReader.h>
And Zxingwidgetcontroller is used in the SSVIEWCONTROLLER.M, and Zxingwidgetcontroller has C + + code, so you need to change the Ssviewcontroller suffix to. mm. Because Ssviewcontroller is called in Ssappdelegate, the. m suffix is also changed to. mm.
Then compile it and find out that the compilation was successful. Then our tutorial is over.
Precautions
This is because the tests folder in the Zxingwidget project has not been deleted and it is OK to delete it.
2, after the deletion of the tests folder, the compilation will be found error,
This is because, without dragging zxingwidget.xcodeproj to and zxing sibling directories, drag zxingwidget.xcodeproj to and zxing sibling directories
3, some people do not like to put zxing files and. Xcodeproj under the same level directory, just like our demo. If it is available elsewhere, it is necessary to modify the path in the header search path. If we put zxing under the testzxing directory,
In this case, you need to modify the header search path:
Share from: http://hi.baidu.com/_delegate/item/56ef8c034c2c3d1aaddc7081