2

アプリに QR コード リーダーを埋め込む必要があります。これまでのところ、ZBarSDK は ios に適したソリューションのようです。いくつかの例とチュートリアルを入手し、機能をアプリにうまく埋め込みました。

ただし、私が見つけたチュートリアルでは、結果をアラートで表示するだけです。

私の場合、使用する QR コードには URL が含まれます。必要なのは、スキャン後に直接 Web を提示することです。ユーザーが簡単にアプリに戻れるように、ナビゲーション バーを含む UIweb ブラウザーで Web を開く必要があります。アプリ開発初心者です。誰かが私にいくつかの解決策を提供できれば幸いです。これはこれまでの私のコードです

- (IBAction)scanButtonPress:(id)sender
{
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;

    [reader.scanner setSymbology:ZBAR_UPCA config:ZBAR_CFG_ENABLE to:0];
    reader.readerView.zoom = 1.0;

    [self presentModalViewController:reader
                            animated:YES];
}

- (void)    imagePickerController:(UIImagePickerController *)reader didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    id <NSFastEnumeration> results = [info objectForKey:ZBarReaderControllerResults];

    ZBarSymbol *symbol = nil;

    for (symbol in results)
    {
        NSString *upcString = symbol.data;

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Scanned UPC" message:[NSString stringWithFormat:@"The UPC read was: %@", upcString] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];

        [alert show];

        [reader dismissModalViewControllerAnimated:YES];
    }
}

コードを変更する必要があることはわかっています

 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Scanned UPC" message:[NSString stringWithFormat:@"The UPC read was: %@", upcString] delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];

    [alert show];

しかし、この関数に到達するための正しいコードが何であるかわかりません。

4

1 に答える 1

3

このコード スニペットがお役に立てば幸いです。

- (void) imagePickerController: (UIImagePickerController*) reader didFinishPickingMediaWithInfo: (NSDictionary*) info
{

  <NSFastEnumeration> results =
        [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    // EXAMPLE: do something useful with the barcode data
    NSString *resultText = symbol.data;

    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    [reader dismissModalViewControllerAnimated: YES];


    BOOL canOpenGivenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:resultText]];

    if (canOpenGivenURL)
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:resultText]];
    else
        // Not valid URL -- show some alert 
}
于 2013-09-06T10:16:50.650 に答える