Iphone 如何通过ZBarSDK从二维码中获取URL并直接在UIWebView中显示
我需要在我的应用程序中嵌入二维码阅读器。到目前为止,ZBarSDK似乎是ios的一个很好的解决方案。我抓取了一些示例和教程,并成功地将该功能嵌入到我的应用程序中 但是,对于我找到的教程,它们都只是显示带有警告的结果 在我的例子中,我将使用的二维码将包含一个url,我需要的是在扫描后直接显示web。需要在包含导航栏的UIweb浏览器中打开web,以便用户可以轻松返回应用程序。 我是应用程序开发的初学者。如果有人能为我提供一些解决方案,我将不胜感激。这是到目前为止我的代码Iphone 如何通过ZBarSDK从二维码中获取URL并直接在UIWebView中显示,iphone,ios,zbar-sdk,Iphone,Ios,Zbar Sdk,我需要在我的应用程序中嵌入二维码阅读器。到目前为止,ZBarSDK似乎是ios的一个很好的解决方案。我抓取了一些示例和教程,并成功地将该功能嵌入到我的应用程序中 但是,对于我找到的教程,它们都只是显示带有警告的结果 在我的例子中,我将使用的二维码将包含一个url,我需要的是在扫描后直接显示web。需要在包含导航栏的UIweb浏览器中打开web,以便用户可以轻松返回应用程序。 我是应用程序开发的初学者。如果有人能为我提供一些解决方案,我将不胜感激。这是到目前为止我的代码 - (IBAction)s
- (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];
}
}
但是,我不知道实现此功能的正确代码是什么。希望此代码片段有助于:
- (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
}
-(void)imagePickerController:(UIImagePickerController*)读卡器已使用信息完成PickingMediaWithInfo:(NSDictionary*)信息
{
结果=
[信息对象forkey:ZBarReaderControllerResults];
ZBarSymbol*符号=nil;
用于(结果中的符号)
//示例:只需抓取第一个条形码
打破
//示例:对条形码数据执行一些有用的操作
NSString*resultText=symbol.data;
//添加:关闭控制器(注意从*读卡器*!)
[reader dismissModalViewControllerAnimated:是];
BOOL CANOPEGIVENURL=[[UIApplication sharedApplication]canOpenURL:[NSURL URLWithString:resultText]];
if(CANOPEGIVENURL)
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:resultText]];
其他的
//无效的URL--显示一些警报
}
您可以从这里找到一些帮助,记录您的upcString,并让我知道您是否能够在该字符串对象上获得确切的所需web链接?您需要在UIweb浏览器中打开URL,或者需要在iphone safari(应用程序的外侧)中打开URL?我需要在包含导航栏的UIweb浏览器中打开URL,以便用户可以轻松返回应用程序。@Richard如果对您有帮助,请将答案标记为已接受。strUrl来自何处?@Mrunal感谢您的宝贵帮助。这些代码对我有用。但是,我需要在UIweb浏览器中打开包含导航栏而不是safari的URL,以便用户可以轻松返回应用程序。您能帮助我更改代码吗?创建一个自定义UIView,其中包含UIWebview和带有后退按钮的导航栏。您需要根据需要添加或删除此视图。并且仅在此UIWebview中使用回迁URL。@谢谢您的解释,我已经创建了一个带有UIWebview和导航栏的自定义UIView,但是在您提供的代码中我应该更改哪些代码?
- (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
}