我有以下代码:
#pragma mark Barcodescanner
- (void)barcodeScanner:(id)sender {
UIWindow *window = [UIApplication sharedApplication].delegate.window;
//UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, window.frame.size.width, window.frame.size.height)];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake((window.frame.size.width - 600) / 2, (window.frame.size.height - 400) / 2, 600, 400)];
//Here it should be checked if the scanner is open, if it is open, the scanner should closed, if the scanner is not open, the scanner should be open
[window addSubview:view];
self.scanner = [[MTBBarcodeScanner alloc] initWithPreviewView:view];
[MTBBarcodeScanner requestCameraPermissionWithSuccess:^(BOOL success) {
if (success) {
[self.scanner startScanningWithResultBlock:^(NSArray *codes) {
[self.scanner stopScanning];
AVMetadataMachineReadableCodeObject *code = [codes firstObject];
NSRange rangeTypeOfEngine = NSMakeRange(0, 2);
NSString *typOfEngine = [code.stringValue substringWithRange:rangeTypeOfEngine];
NSRange rangeSerialNumberOfEngine = NSMakeRange(2, code.stringValue.length - 2);
NSString *serialNumberOfEngine = [code.stringValue substringWithRange:rangeSerialNumberOfEngine];
NSNumberFormatter *f = [[NSNumberFormatter alloc] init];
f.numberStyle = NSNumberFormatterDecimalStyle;
NSNumber *myNumber = [f numberFromString:typOfEngine];
NSString *nameOfEngine;
switch ([myNumber intValue]) {
case 10:
case 11:
case 12:
case 13:
nameOfEngine = @"T100";
break;
default:
nameOfEngine = @"noname";
serialNumberOfEngine = @"";
break;
}
Geraet *newGeraet = [NSEntityDescription insertNewObjectForEntityForName:@"Geraet" inManagedObjectContext:MOC];
newGeraet.einsatzbericht = self.einsatzbericht;
newGeraet.bezeichnung = nameOfEngine;
newGeraet.nummer = serialNumberOfEngine;
[MOC save:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:kUpdateListOfDevices object:nil];
[view removeFromSuperview];
/*
NSArray *codeArray = [code.stringValue componentsSeparatedByString:@"\n"];
[view removeFromSuperview];
DLAVAlertView *alertView = [[DLAVAlertView alloc] initWithTitle:@"Fehler" message:@"Ungültiger Code" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
*/
}];
} else {
[view removeFromSuperview];
}
}];
}
我添加完整的功能,看它会做什么。
我的问题是,当有人点击camperabutton打开扫描仪时,他扫描任何条形码时都无法取消扫描仪。
答案 0 :(得分:0)
相机和警报视图在新窗口中打开,而不是在应用程序窗口中打开。