I have a time issue that has had me stumped I though since I was using a delegate to send the data back to the HomeView to process and redirect out to the ScanResults that was the issue but even if I
[self performSegueWithIdentifier:@"ScanResultsSegue" sender:self];
directly to it I still see a huge delay till the ScanResultsView comes up. Here is the NSLog. Last to lines show the delay
2014-05-24 16:20:55.640 selfcheckin[2748:60b] StartReading Called
2014-05-24 16:21:03.519 selfcheckin[2748:3603] We have a QR -> performSelectorOnMainThread
2014-05-24 16:21:03.522 selfcheckin[2748:3603] IsMainThread: NO
2014-05-24 16:21:03.549 selfcheckin[2748:3603] Barcode: {"stop_id":"3","event_id":"1"}
2014-05-24 16:21:03.555 selfcheckin[2748:3603] didScan Delegate called!
2014-05-24 16:21:03.576 selfcheckin[2748:3603] Parsing Json Dictionary
2014-05-24 16:21:03.584 selfcheckin[2748:3603] Event_id: 1
2014-05-24 16:21:03.590 selfcheckin[2748:3603] Stop_id: 3
2014-05-24 16:21:03.603 selfcheckin[2748:3603] Account_id: 4
2014-05-24 16:21:04.782 selfcheckin[2748:60b] StopReading Called
2014-05-24 16:21:14.721 selfcheckin[2748:3603] Made it to Success!!!
Its taking 10 seconds to transition to the ScanResultsPage .......... I cant find what would be causing it in my code. Should it take that long?? Relevant parts to the
- (BOOL)startReading {
NSError *error;
AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
if (!input) {
NSLog(@"%@", [error localizedDescription]);
return NO;
}
_captureSession = [[AVCaptureSession alloc] init];
[_captureSession addInput:input];
AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
[_captureSession addOutput:captureMetadataOutput];
dispatch_queue_t dispatchQueue;
dispatchQueue = dispatch_queue_create("myQueue", NULL);
[captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
[captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
_videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
[_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[_videoPreviewLayer setFrame:_viewPreview.layer.bounds];
[_viewPreview.layer addSublayer:_videoPreviewLayer];
[_captureSession startRunning];
NSLog(@"%@",@"StartReading Called");
return YES;
}
-(void)stopReading{
[_captureSession stopRunning];
_captureSession = nil;
[_videoPreviewLayer removeFromSuperlayer];
NSLog(@"%@",@"StopReading Called");
}
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
if (metadataObjects != nil && [metadataObjects count] > 0) {
AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];
if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {
NSLog(@"We have a QR -> performSelectorOnMainThread");
NSLog(@"IsMainThread: %@", ([NSThread isMainThread]) ? @"YES" : @"NO");
[self performSelectorOnMainThread:@selector(stopReading) withObject:nil waitUntilDone:NO];
_isReading = NO;
NSLog(@"Barcode: %@",[(AVMetadataMachineReadableCodeObject *)metadataObj stringValue]);
//NSLog(@"Now performSegueWithIdentifier");
//[self performSegueWithIdentifier:@"ScanResultsSegue" sender:self];
NSLog(@"didScan Delegate called!");
[self.scandelegate didScan:self barcodedata:[(AVMetadataMachineReadableCodeObject *)metadataObj stringValue]];
}
}
}