2012-09-08 33 views
8

我已經將zXing項目加載到我自己的項目中。 加載正常,zXing掃描器在按鈕調用後彈出。iPhone zXing QR掃描儀 - didscanresult功能永遠不會觸發

我可以關閉zxingControllerDidCancel上的視圖控制器,但是當我掃描QR碼時,無法識別任何代碼,因此didScanResult函數從不會觸發。

有沒有人對此有任何意見?

didScanResult函數如下。

-(void)zxingController:(ZXingWidgetController *)controller didScanResult:(NSString *)result{ 
resultLabel.text = result; 
NSLog(@"did scan!!!"); 
[self dismissModalViewControllerAnimated:NO]; 

}

注:我不知道這是否是相關的,但是當掃描儀來了,我得到這個記錄由應用:「wait_fences:未能收到回覆:10004003」

+0

你可以發佈你如何創建和顯示ZXingWidgetController嗎? –

+0

基本上我通過這個教程將它添加到我的項目(http://yannickloriot.com/2011/04/how-to-install-zxing-in-xcode-4/) 所以我將它們導入到我的viewcontrollers .h文件 使用ZXingDelegate的'didScanResult'和'zxingControllerDidCancel'功能。如前所述,zxingControllerDidCancel完美工作。 這有幫助嗎? –

+0

看看[這個問題](http://stackoverflow.com/questions/1371346/wait-fences-failed-to-receive-reply-10004003)來解決10004003錯誤。 – Daniel

回答

4

該教程沒有提到您必須將QRCodeReader添加到您的ZXingWidgetController的讀取器集合中。

ZXingWidgetController有一個名爲readers的屬性,它是一個包含讀者實例的NSSet(例如QRCodeReader的實例)。粗略地說,讀者的任務是分析你的相機拍攝的圖像並提取編碼後的信息。你的ZXingWidgetController必須知道它應該使用的讀者,否則它沒有機會做任何有意義的事情。所以你必須在展示ZXingWidget之前設置readers屬性。

ZXing項目有一個示例應用程序演示了這一點。如果你使用ARC,那麼

ZXingWidgetController *widController = [[ZXingWidgetController alloc] initWithDelegate:self showCancel:YES OneDMode:NO]; 
QRCodeReader* qRCodeReader = [[QRCodeReader alloc] init]; 
NSSet *readers = [[NSSet alloc] initWithObjects:qRCodeReader,nil]; 
widController.readers = readers; 
[self presentModalViewController:widController animated:YES]; 

應該做的。

+0

你確定是冠軍!非常感謝您的幫助 - 它現在工作完美:) –