我在我的應用程序中使用ZBarSDK(http://zbar.sourceforge.net/iphone/)。它工作正常,速度非常快,但我發現了一個問題。 我得到這個警告在控制檯和掃描儀viewController永遠不會解僱。只有當我嘗試掃描我已經關注的條形碼時纔會發生。我的意思是,當我按下打開reader viewController的按鈕,然後將相機對準條形碼的位置時,它可以正常工作,viewController會消失,並且會得到代碼。但問題是,我已經將iPad專注於條形碼,然後按下閱讀器按鈕。閱讀器viewController是呈現,我得到的代碼,但viewController並沒有被解僱,我得到這個警告:ZBarSDK不關閉viewController
警告:嘗試從視圖控制器,當演示或解僱正在進行中!
這是所使用的代碼:
- (void)escanearCodigo
{
ZBarReaderViewController *escanearVC = [ZBarReaderViewController new];
escanearVC.readerDelegate = self;
escanearVC.supportedOrientationsMask = ZBarOrientationMaskAll;
// Presentar pantalla escaneo
[self presentViewController:escanearVC animated:YES completion:nil];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// Obtener el resultado del escaneo
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
//Almacenar el codigo de barras
break;
NSLog(@"Code: %@", symbol.data);
[reader dismissViewControllerAnimated:YES completion:nil];
}
我希望我已經提前解釋以及:)
感謝。
更新: 到現在爲止,最好的「半解」是下一個: 把didFinishPickingMediaWithInfo代碼中的if語句,以防止這個代碼將EXEC時的viewController是沒有尚未呈現(我認爲) :
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
if (![reader isBeingPresented]) {
// Obtener el resultado del escaneo
id<NSFastEnumeration> results = [info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
//Almacenar el codigo de barras
break;
[reader dismissViewControllerAnimated:YES completion:nil];
}
}
當viewcontroller沒有被解僱時調用'didFinishPickingMediaWithInfo'方法嗎?你用NSLog測試過它嗎? – pmk
謝謝!我在if(![reader isBeingPresented])中寫了didFinishPickingMediaWithInfo,並且警告消失了,但我需要將另一個區域(不帶條形碼)聚焦,然後將其聚焦到條形碼區域進行掃描。直到現在,這是最好的解決方案:)謝謝你! – javiazo
嘗試刷新ZBarReaderView的緩存,每當呈現ZBarreaderViewcontroller * [escanearVC.readerView flushCache]; * – Bala