Instructions for using the iPhone QR code for in-depth resolution

Source: Internet
Author: User

In-depth analysisIPhone QR codeInstructions for use are described in this article,QR codeIt records the data symbol information by using a specific ry that is distributed in the two-dimensional direction of the plane according to a certain rule. Not to mention, we will go directly to o'connor for details.

1. Introduction to QR code

QR code2-dimen1_bar code) records the data symbol information using a specific ry that is distributed in two-dimensional directions of the plane according to a certain pattern; the concept of "0" and "1" bit streams that constitute the internal logic of computers is cleverly used in code compilation, A number of ry corresponding to the binary are used to represent the numerical value of the text. The image input device or the photoelectric scanning device can automatically read and read the text to achieve automatic information processing: the two-dimensional Barcode/QR code can express information both horizontally and vertically, so it can express a large amount of information in a small area.

2. Get the iphone open source code project

Http://code.google.com/p/zxing/

First, download the open-source code directly from the address above the tool. For details, see Figure 1.

After downloading the package to your local computer, decompress the package and enter the folder.

Iphone folder --> (click to enter)

ScanTest (test project) and ZXingWidget (Connection Library.)

3. Compile the ZXingWidget and call it in the project.

The AVCaptureDeviceInput AVCaptureVideoDataOutput class is available for cameras above 4.0 (in this way, we can automatically focus on the QR code on 4.x to obtain the QR code information)

In the static library of ZXingWidget

ZXingWidgetController. h provides us with the HAS_AVFF judgment switch. The default value is 1)

In this case, the ZXingWidget project can only select Base SDK 4.0.

2

Can pass

After compiling. a, select Base SDK 4.0 as the ScanTest project to compile and run the project successfully.

For details about calling QR code decoding, see

The RootViewController. mm file shows the method.

// This method calls automatic focus Decoding of camera data.

 
 
  1. -(IBAction) scanPressed :( id) sender
  2. {
  3. // For the code here, see the project
  4. }
  5. // The following delegate method returns the decoded result
  6. # Pragma mark ZXingDelegateMethods
  7.  
  8. -(Void) zxingController :( ZXingWidgetController *) controller didScanResult :( NSString *) result
  9. {
  10. }

In fact, the program that we can compile can be run on machines above 4.x.

However, only 4.x is supported in this way. Is it not supported in this case?

Yes, but we need to modify and add some code.

First, make sure that the static library. a and the calling program are compiled in bade sdk 4.0.

However, you need to modify the settings of the project in the calling program such as ScanTest.

3, 4

 

After modifying the settings, copy the following code to replace the original one.

ScanPressed Method

 
 
  1. -(IBAction) scanPressed :( id) sender {
  2. If (NSClassFromString (@ "AVCaptureSession") & NSClassFromString (@ "AVCaptureVideoPreviewLayer "))
  3. {
  4. MLOG (@ "_ IPHONE_4_0 ");
  5. ZXingWidgetController * widController = [[ZXingWidgetController alloc] initWithDelegate: self showCancel: YES OneDMode: NO];
  6. WidController. view. backgroundColor = [UIColor blueColor];
  7. QRCodeReader * qrcodeReader = [[QRCodeReader alloc] init];
  8. NSSet * readers = [[NSSet alloc] initWithObjects: qrcodeReader, nil];
  9. [QrcodeReader release];
  10. WidController. readers = readers;
  11. [Readers release];
  12. NSBundle * mainBundle = [NSBundle mainBundle];
  13. WidController. soundToPlay =
  14. [NSURL fileURLWithPath: [mainBundle pathForResource: @ "beep-beep" ofType: @ "aiff"] isDirectory: NO];
  15. [Self presentModalViewController: widController animated: YES];
  16. [WidController release];
  17. }
  18. Else // firmware system below 3.x */
  19. {
  20. MLOG (@ "_ IPHONE_3_0 ");
  21. UIImagePickerController * pickCtr = [[UIImagePickerController alloc] init];
  22. PickCtr. sourceType = UIImagePickerControllerSourceTypeCamera;
  23. PickCtr. delegate = self;
  24. [Self presentModalViewController: pickCtr animated: YES];
  25. [PickCtr release];
  26. }
  27. }
  28. # Pragma mark-
  29. # Pragma mark UIImagePickerControllerDelegate
  30.  
  31. -(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info
  32. {
  33. NSLog (@ "info ===%@", info );
  34. UIImage * image = [info objectForKey: @ "UIImagePickerControllerOriginalImage"];
  35. QRCodeReader * qrcodeReader = [[QRCodeReader alloc] init];
  36. NSSet * readers = [[NSSet alloc] initWithObjects: qrcodeReader, nil];
  37. [QrcodeReader release];
  38. CGRect cropRect = [UIScreen mainScreen]. applicationFrame;
  39. Decoder * d = [[Decoder alloc] init];
  40. D. readers = readers;
  41. D. delegate = self;
  42. Int res = [d decodeImage: image];
  43. MLOG (@ "res = % d", res );
  44. [D release];
  45. [Self dismissModalViewControllerAnimated: YES];
  46. }
  47. -(Void) decoder :( Decoder *) decoder didDecodeImage :( UIImage *) image usingSubset :( UIImage *) subset withResult :( TwoDDecoderResult *) twoDResult {
  48. MLOG (@ "twoDResult text ==%@", [twoDResult text]);
  49. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle: [twoDResult text] message: [twoDResult text]
  50. Delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil];
  51. [AlertView show];
  52. [AlertView release];
  53. }
  54.  
  55. -(Void) decoder :( Decoder *) decoder failedToDecodeImage :( UIImage *) image usingSubset :( UIImage *) subset reason :( NSString *) reason {
  56. MLOG (@ "twoDResult text === failedToDecodeImage ");
  57. Decoder. delegate = nil;
  58. }

In this way, different decoding methods can be automatically identified by the sub-firmware after 4.0 compilation.

For more than 4.0 of them, we try to automatically decode the QR code.

In versions lower than 4.0, we tried to call the camera function and then decode the captured image.

4. Simulate the QR code test data by yourself

You can enter

Http://chart.apis.google.com/chart? Cht = qr & chs = 150x150 & chlorophyll = http://www.hiapk.com

We can see the open-source QR code of google 5.

Cht indicates the type of the generated QR code.

Chs indicates the size of the generated QR code.

Chlorophyll indicates the information displayed on the QR code.

The above information can be modified by yourself (it is best not to modify the cht QR code type) and then tested using the program compiled just now.

The correct result will be decoded.

Summary: in-depth analysisIPhone QR codeI hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.