二维码的扫描

扫描二维码SDK:ZBarSDK..

生成二维码SDK:QREncoder

参考:http://blog.csdn.net/miracle_of_thinking/article/details/7576532


系统定制的方式。

- (void)btnPressed:(UIButton *)btn

{

    if ([ZBarReaderViewControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        ZBarReaderViewController *imagePicker = [[ZBarReaderViewControlleralloc]init];

        imagePicker.readerDelegate =self;

        imagePicker.sourceType =UIImagePickerControllerSourceTypeCamera;

        [selfpresentViewController:imagePickeranimated:YEScompletion:^{

           //

        }];

    }

}


#pragma mark - delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    id<NSFastEnumeration> results = [infoobjectForKey:ZBarReaderControllerResults];

   ZBarSymbol *symbol =nil;

   NSString *data =nil;

   for (symbolin results) {

       if ([symbol.typeNameisEqualToString:@"QR-Code"]) {

            data = symbol.data;

           break;

        }

    }

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:data]];

}


自定制的实现方式:

- (void)viewDidLoad

{

    [superviewDidLoad];

    ZBarImageScanner *imageScanner = [[ZBarImageScanneralloc] init];

    [imageScanner setSymbology:ZBAR_QRCODEconfig:ZBAR_CFG_X_DENSITYto:0];

    ZBarReaderView *readerView = [[ZBarReaderViewalloc] initWithImageScanner:imageScanner];

    readerView.frame =CGRectMake(30, 30, 260, 260);

    readerView.readerDelegate =self;

    readerView.tracksSymbols =YES;

    readerView.trackingColor = [UIColorwhiteColor];

    [self.viewaddSubview:readerView];

    [readerViewstart];

    

}


- (void) readerView: (ZBarReaderView*) readerView

     didReadSymbols: (ZBarSymbolSet*) symbols

          fromImage: (UIImage*) image

{

   ZBarSymbol *symbol = nil;

   NSString *data = nil;

   for (symbol in symbols) {

       if ([symbol.typeNameisEqualToString:@"QR-Code"]) {

            data = symbol.data;

           break;

        }

    }

    [[UIApplicationsharedApplication] openURL:[NSURLURLWithString:data]];

}





你可能感兴趣的:(二维码的扫描)