gpt4 book ai didi

iphone - 如何通过ZBarSDK从二维码中获取URL并直接呈现在UIWebView中

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:08:57 25 4
gpt4 key购买 nike

我需要在我的应用程序中嵌入二维码阅读器。到目前为止,ZBarSDK 似乎是一个很好的 ios 解决方案。我抓取了一些示例和教程,并成功地将功能嵌入到我的应用程序中。

但是,对于我找到的教程,都只是显示带有警报的结果。

在我的例子中,我将要使用的二维码将包含一个 url,我需要的是在扫描后直接呈现网页。 Web 需要在包含导航栏的 UIweb 浏览器中打开,以便用户可以轻松返回应用程序。我是应用程序开发的初学者。如果有人能为我提供一些解决方案,我将不胜感激。到目前为止,这是我的代码

- (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];

但我不知道实现此功能的正确代码是什么。

最佳答案

希望这段代码对您有所帮助:

- (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
}

关于iphone - 如何通过ZBarSDK从二维码中获取URL并直接呈现在UIWebView中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18655130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com