Created
March 19, 2013 01:53
-
-
Save helloworld116/5193035 to your computer and use it in GitHub Desktop.
ios:二维码扫描关键代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // RootViewController.m | |
| // ScranDemo | |
| // | |
| // Created by apple on 13-2-22. | |
| // Copyright (c) 2013年 __MyCompanyName__. All rights reserved. | |
| // | |
| #import "RootViewController.h" | |
| @interface RootViewController () | |
| @end | |
| //important:扫描二维码需要导入ZBarSDK | |
| @implementation RootViewController | |
| @synthesize resultImageView;//用于显示摄像头拍摄的图片 | |
| @synthesize resultTextView;//用于显示二维码扫描后的信息,一般是url | |
| - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil | |
| { | |
| self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; | |
| if (self) { | |
| // Custom initialization | |
| } | |
| return self; | |
| } | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| // Do any additional setup after loading the view. | |
| } | |
| - (void)viewDidUnload | |
| { | |
| [self setResultImageView:nil]; | |
| [self setResultTextView:nil]; | |
| [super viewDidUnload]; | |
| // Release any retained subviews of the main view. | |
| } | |
| - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
| { | |
| return (interfaceOrientation == UIInterfaceOrientationPortrait); | |
| } | |
| - (IBAction)scan:(id)sender { | |
| ZBarReaderViewController *reader = [ZBarReaderViewController new]; | |
| reader.readerDelegate = self; | |
| reader.supportedOrientationsMask = ZBarOrientationMaskAll; | |
| ZBarImageScanner *scaner = reader.scanner; | |
| [scaner setSymbology:ZBAR_I25 config:ZBAR_CFG_ENABLE to:0]; | |
| [self presentModalViewController:reader animated:YES]; | |
| } | |
| -(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ | |
| id<NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults]; | |
| ZBarSymbol *symbol = nil; | |
| for (symbol in results) { | |
| break; | |
| } | |
| // if ([symbol.data canBeConvertedToEncoding:NSShiftJISStringEncoding]) | |
| // { | |
| // NSString *str = [NSString stringWithCString:[symbol.data cStringUsingEncoding: NSShiftJISStringEncoding] encoding:NSUTF8StringEncoding]; | |
| // } | |
| NSLog(@"%s %d",__FUNCTION__,__LINE__); | |
| NSLog(@"the result is %@",symbol.data); | |
| resultTextView.text = symbol.data; | |
| resultImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage ]; | |
| [picker dismissModalViewControllerAnimated:YES ]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment