Cancel button action in zbar shows blank view

547 views Asked by At

I am using tab bar in my iOS app. When I tap on the scan tab, i invoked the delegate method to start the camera immediately on scan tab. When I start the camera to scan the QR Code and tap on cancel button before scanning, I get the blank view. How to display the view when camera is dismissed

- (void) openCameraScanner
{
    ZBarReaderViewController *reader = [[ZBarReaderViewController alloc] init];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;
    reader.showsZBarControls = YES;

    ZBarImageScanner *scanner = reader.scanner;
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];
    [self presentViewController:reader animated:YES completion:nil];
    reader.showsZBarControls = YES;
    //reader.cameraOverlayView = [self commonOverlay];
}

- (void) imagePickerController: (UIImagePickerController*) reader
 didFinishPickingMediaWithInfo: (NSDictionary*) info
{
    // ADD: get the decode results
    id<NSFastEnumeration> results =
    [info objectForKey: ZBarReaderControllerResults];
    ZBarSymbol *symbol = nil;
    for(symbol in results)
        // EXAMPLE: just grab the first barcode
        break;

    // EXAMPLE: do something useful with the barcode data
    //resultsView.text = symbol.data;
    NSString *urlString = symbol.data;
    NSURL *url = [NSURL URLWithString:urlString];
    NSLog(@"Query after scan = %@", [url query]);

    //Extract id from URL which is there in QR Code --- start
    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] init];
    for(NSString *param in [urlString componentsSeparatedByString:@"&"])
    {
        NSArray *elements = [param componentsSeparatedByString:@"="];
        if([elements count]<2)
            continue;
        [dictionary setObject:[elements objectAtIndex:1] forKey:[elements objectAtIndex:0]];
        NSLog(@"value is == %@", [elements objectAtIndex:1]);
    //Extract id from URL which is there in QR Code --- end

        if([[elements objectAtIndex:1] intValue])
        {
            NSUserDefaults *defaultsForAsk = [NSUserDefaults standardUserDefaults];
            idToAsk = [NSString stringWithFormat:@"%d",[[elements objectAtIndex:1] intValue]];
            [defaultsForAsk setObject:idToAsk forKey:@"IDTOASKVIEW"];


            flagToShowView = YES;
            listViewCntrl.getFlag = flagToShowView;
            [self viewDidLoadForDynamicFields];

        }
        else if([elements objectAtIndex:1] == [NSNull null])
        {
            [reader dismissViewControllerAnimated:YES completion:Nil];
            UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Invalid QR Code scanned" message:@"Please scan Collaborator's QR Code" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [message show];
        }
    }

    image.image =
    [info objectForKey: UIImagePickerControllerOriginalImage];

    // ADD: dismiss the controller (NB dismiss from the *reader*!)
    //[reader dismissViewControllerAnimated:YES completion:nil];

    [reader dismissViewControllerAnimated:YES completion:Nil];

}
1

There are 1 answers

1
Ilyas On

You can re display the view using -(void)viewWillAppear:(BOOL)animated method of your ViewController class.