Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: pressing cancel doesn't stop scanning #60

Open
jakolion opened this issue Nov 16, 2018 · 12 comments

Comments

Projects
None yet
9 participants
@jakolion
Copy link

commented Nov 16, 2018

This is my code:

String data = "";
try {
    data = await BarcodeScanner.scan();
} on PlatformException catch ( e ) {
    if ( e.code == BarcodeScanner.CameraAccessDenied ) {
        _log.warning( "camera permission not granted" );
        return;
    }
    else {
        _log.warning( "$e" );
        return;
    }
} on FormatException {
    // scan was canceled by user
    _log.info( "scan canceled by user" );
    return;
}
catch ( e ) {
    _log.warning( "$e" );
    return;
}

Pressing cancel when the camera is turned on, I expect the "FormatException". On Android this is working fine. On iOS, the flash is turned off, the camera screen is popped and the view is going back the the previous page as expected. But in the background the scanning is still active and the code above is still in line 3. When holding the phone over a QR code it is scanned successfully and the code above is continuing.

Tested with iOS 11.4 (15F79) on iPhone 5s and with iOS 12.1 (16B92) on iPhone 8.

@jakolion

This comment has been minimized.

Copy link
Author

commented Nov 21, 2018

Fixed with the mentioned merge request #55 and release 0.0.8. Can be closed.

@lauraseidler

This comment has been minimized.

Copy link

commented Feb 13, 2019

@jakolion do you get the FormatException on iOS? For me the scanner now stops and disappears, but I get neither an exception (not even in the last general catch block), nor a result.

@jakolion

This comment has been minimized.

Copy link
Author

commented Feb 13, 2019

@jakolion do you get the FormatException on iOS? For me the scanner now stops and disappears, but I get neither an exception (not even in the last general catch block), nor a result.

You are describing the behavior I had before version 0.0.8. The scanner disappeared and the previous page was shown but it was still running in the background.
With release 0.0.8 it worked the same way as before and throws the FormatException when canceling.
https://pub.dartlang.org/packages/barcode_scan/versions/0.0.8

@lauraseidler

This comment has been minimized.

Copy link

commented Feb 13, 2019

You are describing the behavior I had before version 0.0.8. The scanner disappeared and the previous page was shown but it was still running in the background.

Not quite - the scanner is off, as far as I can see, but I'm still not getting any Exception (or empty result). It feels like the Future is somehow not resolving at all (and I have 0.0.8).

@jakolion

This comment has been minimized.

Copy link
Author

commented Feb 13, 2019

Not quite - the scanner is off, as far as I can see, but I'm still not getting any Exception (or empty result). It feels like the Future is somehow not resolving at all (and I have 0.0.8).

After cancelling the scanner was still active in line 3 of my code above. There wasn't any result or exception as well. If you are really using version 0.0.8 then I don't have any idea. Currently it's working fine for me.

@theneedyguy

This comment has been minimized.

Copy link

commented Feb 26, 2019

I have the same issue. The app on iOS does not throw the format exception when I press cancel. Using 0.0.8 too.

@mdudek

This comment has been minimized.

Copy link

commented Mar 11, 2019

I'm facing same issue as @theneedyguy with version 0.0.8.

@ricpar11

This comment has been minimized.

Copy link

commented Mar 11, 2019

still having this error in version 1.0.0, any fix?

@JohanSnygg

This comment has been minimized.

Copy link

commented Mar 25, 2019

I have no way of testing this, but I may have a fix if someone could test it out and then commit it to the branch.

in the file BarcodeScannerViewController.m change the method "cancel" to:

- (void)cancel {
[self.delegate barcodeScannerViewController:self didFailWithErrorCode:@"USER_CANCELED"];
[self dismissViewControllerAnimated:true completion:nil];
}

and in barcode_scan.dart add:

static const UserCancelled = 'USER_CANCELED';

for use in exception handling around BarcodeScanner.scan();

Hope this helps

@DuskMount

This comment has been minimized.

Copy link

commented Jun 9, 2019

I have the same issue when using 1.0.0

@ashkryab

This comment has been minimized.

Copy link

commented Jun 22, 2019

I have the same issue 1.0.0

@lookfirst

This comment has been minimized.

Copy link

commented Jul 13, 2019

Ok, I figured it out, something just started working after resetting my codebase:

Per instructions from @JohanSnygg above. This seems pretty obvious now... cancel is called, but nothing is returned, so the Future in Dart never completes...

- (void)cancel {
    [self.delegate barcodeScannerViewController:self didFailWithErrorCode:@"USER_CANCELED"];
    [self dismissViewControllerAnimated:true completion:nil];
}

Now we can check for the PlatformException:

class BarcodeScanner {
  static const CameraAccessDenied = 'PERMISSION_NOT_GRANTED';
  static const UserCanceled = 'USER_CANCELED';
  static const MethodChannel _channel =
      const MethodChannel('com.apptreesoftware.barcode_scan');
  static Future<String> scan() async => await _channel.invokeMethod('scan');
}

I think this was the final goodness, change to copy (Also fixes warning in xcode)...

@property(nonatomic, copy) FlutterResult result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.