自从升级到 XCode 5/iOS 7 后,在调用应该呈现 Redlaser SDK 条形码选择器控制器的函数时出现以下错误:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“应用程序试图在目标上呈现一个 nil 模态视图控制器。” *首先抛出调用栈:
(
0 CoreFoundation 0x02ef25e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x028dd8b6 objc_exception_throw + 44
2 UIKit 0x006e817a -[UIViewControllerpresentViewController:withTransition:completion:] + 4879
3 UIKit 0x006e8caf -[UIViewController presentViewController:animated:completion:] + 130
4 UIKit 0x006e8cef -[UIViewController presentModalViewController:animated:] + 56
5 Extinguishers 0x0000b703 -[LoginViewController scanPressed] + 1299
这是我的方法导致它:
-(IBAction) scanPressed
{
if (overlayController.parentPicker == nil)
{
BarcodePickerController * picker = [[BarcodePickerController alloc] init];
[picker setOverlay:overlayController];
[picker setDelegate:self];
// Initialize with portrait mode as default
picker.orientation = UIImageOrientationUp;
// The active scanning region size is set in OverlayController.m
}
// Update barcode on/off settings
[overlayController.parentPicker setScanUPCE:YES];
[overlayController.parentPicker setScanEAN8:YES];
[overlayController.parentPicker setScanEAN13:YES];
//[overlayController.parentPicker setScanSTICKY:YES];
//[overlayController.parentPicker setScanQRCODE:YES];
[overlayController.parentPicker setScanCODE128:YES];
[overlayController.parentPicker setScanCODE39:YES];
[overlayController.parentPicker setScanITF:YES];
// Data matrix decoding does not work very well so it is disabled for now
[overlayController.parentPicker setScanDATAMATRIX:NO];
// hide the status bar
[[UIApplication sharedApplication] setStatusBarHidden:YES];
// Show the scanner overlay - THIS LINE CAUSES THE CRASH
[self presentModalViewController:overlayController.parentPicker animated:TRUE];
}
我也试过升级到最新版的Redlaser SDK,还是一样。在切换到 iOS 7 作为基础 SDK 之前,我没有遇到这个问题。