BarcodeScanner icon indicating copy to clipboard operation
BarcodeScanner copied to clipboard

Scanner appears to "freeze".

Open qrux opened this issue 10 years ago • 20 comments

I managed to get the plugin installed on PhoneGap 3.0.0, using plugman. I'm using XCode 4.6.1. My device is an iPhone 4S, running 6.1.3.

When the scanner starts on my device (obviously not the sim, since the sim doesn't emulate capture), it looks like it takes a single still, and then "freezes". The "Cancel" button works, but the scanner doesn't appear to be doing anything.

I see these errors:

WARNING: -[<AVCaptureVideoPreviewLayer: 0x210963b0> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported
WARNING: -[<AVCaptureVideoPreviewLayer: 0x210963b0> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
WARNING: -[<AVCaptureVideoPreviewLayer: 0x210963b0> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
Warning: Attempt to present <CDVbcsViewController: 0x2108fa90> on <MainViewController: 0x1fd6ff90> while a presentation is in progress!
Warning: Attempt to present <CDVbcsViewController: 0x210b15b0> on <MainViewController: 0x1fd6ff90> whose view is not in the window hierarchy!
Warning: Attempt to present <CDVbcsViewController: 0x210b27b0> on <MainViewController: 0x1fd6ff90> whose view is not in the window hierarchy!

Is there something I can do to get this working? The code itself is entirely vanilla.:

        var scanner = cordova.require("cordova/plugin/BarcodeScanner");

        //cordova.plugin.barcodeScanner.scan(
        scanner.scan(
          function ( result ) {
              alert("We got a barcode\n" +
                    "Result: " + result.text + "\n" +
                    "Format: " + result.format + "\n" +
                    "Cancelled: " + result.cancelled);
          },
          function ( error ) {
              alert("Scanning failed: " + error);
          }

I appreciate anyone taking the time to look at this, and I'm happy to provide more info as necessary.

qrux avatar Sep 18 '13 21:09 qrux

An update on the issue: once the freeze occurs, it can be "unfrozen" by clicking on the lock button (physical button on top of iPhone), and then going back to the app (click again, unlock).

This will cause the scanner to "go live" and hunt for barcodes.

Again, I would appreciate anyone who will take the time to look at this issue, and help determine if it's user error on my part or an issue with the PG version bump or maybe a problem with my specific iOS version. Of course, I will keep searching for a solution...

qrux avatar Sep 20 '13 00:09 qrux

+1

AVVS avatar Sep 22 '13 14:09 AVVS

What version of the plugin have you installed?

wildabeast avatar Sep 25 '13 00:09 wildabeast

0.7.2 as it seems,

AVVS avatar Sep 25 '13 07:09 AVVS

Whichever was current as of a week ago when I ran this:

plugman install --platform ios --project ~/big/proj/XXXX/platforms/ios --plugin https://github.com/phonegap-build/BarcodeScanner

I'd give more info, except that 'plugman info' is completely unintuitive. How do I find the version once the plugin has been installed?

I realize this is my opinion, but I'm not terribly concerned with an iOS 7-related update, because I'm concerned that upgrading PhoneGap and iOS is going to cause more issues for my app. I'd rather see a fix (whether in the plugin or my usage) for iOS 6. Of course, IDK how others uses feel.

Thanks again for taking a look.

qrux avatar Sep 25 '13 11:09 qrux

Seems a bit wierd that you are using (and are even able to use) the cordova.require method to access the scanner, when the current implementation doesn't actually use cordova.define, it uses js-modules (see the current js file here and the commit which made this change here). Makes me wonder whether the version you are using is actually 3.0 compatible? I'm not sure how to check what version plugman actually installed for you. Note that you can use plugman uninstall to remove and try again.

I just tested it out and it worked fine for me, on an iPhone 5 and an iPod Touch 4th gen. Possible that your device is munged? Maybe you can recreate my this simple app to see if its your device, or your implementation:

Create the PhoneGap application: /phonegap/phonegap-3.0.0/lib/ios/bin/create ~/repo/IOSprojects/ScannerThree com.ryan.scannerthree ScannerThree

Install the BarcodeScanner plugin: plugman install --platform ios --project ~/repo/IOSprojects/ScannerThree/ --plugin https://github.com/wildabeast/BarcodeScanner.git

Don't include barcodescanner.js -- Cordova loads it using the js-module tag. Then, sample js call: https://github.com/wildabeast/BarcodeDemo/blob/three-oh/js/index.js#L57

If that still doesn't work, maybe its your device?

wildabeast avatar Sep 25 '13 20:09 wildabeast

Current version works just fine - I was able to fix it. Its just that phonegap builder has no idea of new cordova, so thats where the issue was. Building manually works great. Example config below:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.example.hello" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>InFood</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="[email protected]" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <access origin="*" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="false" />

    <feature name="Camera">
        <param name="ios-package" value="CDVCamera" />
    </feature>

    <feature name="Capture">
        <param name="ios-package" value="CDVCapture" />
    </feature>

    <feature name="NetworkStatus">
        <param name="ios-package" value="CDVConnection" />
    </feature>

    <feature name="SplashScreen">
        <param name="ios-package" value="CDVSplashScreen" />
    </feature>

    <feature name="BarcodeScanner">
        <param name="ios-package" value="CDVBarcodeScanner" />
    </feature>

</widget>

AVVS avatar Sep 25 '13 20:09 AVVS

This is where the issue is for me:

plugman install --platform ios --project ~/repo/IOSprojects/ScannerThree/ --plugin https://github.com/wildabeast/BarcodeScanner.git

I wasn't able to get my system working with calling plugman this way. I did it like this (using your values):

plugman install --platform ios --project ~/repo/IOSprojects/ScannerThree/platforms/ios --plugin https://github.com/wildabeast/BarcodeScanner.git

I did that because when I did it the way you suggested above (at the "root" of my PhoneGap project), plugman wiped out of my core cordova plugins. I will try your test project and see.

qrux avatar Oct 04 '13 05:10 qrux

I've changed the code where the captured frames was invoked in another thread. This method has resolved the freeze issue I faced. Please check 34ad5e6

Beside for the warning Warning: Attempt to present <CDVbcsViewController: 0x2108fa90> on <MainViewController: 0x1fd6ff90> while a presentation is in progress! This is due to multiple call to open the scanner in javascript. Make sure your javascript code just invoke the opening of scanner at one time.

khayong avatar Jan 02 '14 05:01 khayong

I just met the same issue, could anyone help to solve this issue?

wahyd4 avatar Feb 08 '14 08:02 wahyd4

The following is the error message from my application:

2014-02-08 17:21:08.823 Libr[322:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x14dbfaf0> isOrientationSupported] is deprecated.  Please use AVCaptureConnection's -isVideoOrientationSupported
2014-02-08 17:21:08.824 Libr[322:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x14dbfaf0> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
2014-02-08 17:21:08.845 Libr[322:60b] WARNING: -[<AVCaptureVideoPreviewLayer: 0x14dbfaf0> setOrientation:] is deprecated.  Please use AVCaptureConnection's -setVideoOrientation:
2014-02-08 17:21:09.113 Libr[322:60b] Warning: Attempt to present <CDVbcsViewController: 0x14efb330> on <MainViewController: 0x14d5bdb0> while a presentation is in progress!

wahyd4 avatar Feb 08 '14 09:02 wahyd4

Finally I used @khayong his forked repo to make this scanner work.

https://github.com/khayong/BarcodeScanner.git

wahyd4 avatar Feb 11 '14 05:02 wahyd4

i got the same issue, and fixed it by changing [self performSelector:@selector(openDialog) withObject:nil afterDelay:1]; to [self performSelector:@selector(openDialog) withObject:nil afterDelay:2];

I guess that scan view become freeze because capture session is no ready, and present scan view with enable animated will cause more time.

lewislone avatar Apr 18 '14 09:04 lewislone

I know that iOS provided the API to scan the barcode, but I am not familiar with iOS development, hope someone can use the native API to build a new plugin.

wahyd4 avatar Apr 19 '14 04:04 wahyd4

How do you solve this??

WARNING: -[<AVCaptureVideoPreviewLayer: 0x1554aed0> setOrientation:] is deprecated. Please use AVCaptureConnection's -setVideoOrientation:

mirko77 avatar May 19 '14 10:05 mirko77

Check out eab62c367b68117de3b42eb889141801e8403612 for solving the deprecated message.

khayong avatar Oct 18 '14 00:10 khayong

  • 1 I'm having the same problem using @ngCordova BarcodeScanner ( http://ngcordova.com/ ). It only happens on iOS and not on Android. I'm quite lost here... some help would be much apreciated! thanx!

javifr avatar Dec 17 '14 16:12 javifr

Let me just confirm what @javifr is saying here, altought without the Android bit.

The issue happens when i try to open the scanner by "code" basically. instead of invoking the same method by the press of a button.

Cnordbo avatar Feb 23 '15 09:02 Cnordbo

I was having the same issue ... it turned out to be the event that triggered the scan, got fired twice within a short time period.

While not a bug with the scanner, it might help to make sure there's not a bug in your application that's causing a double call to cordova.plugin.barcodeScanner.scan

bcentinaro avatar Feb 26 '15 13:02 bcentinaro

I easily fix this creating a global bool variable and set it as "NO" by default then in "CDVBarcodeScanner.mm" I name it BOOL isDialogOpened = NO ; then search for this function - (void)scan:(CDVInvokedUrlCommand*)command and make a conditional check over there like this :

//--------------------------------------------------------------------------
- (void)scan:(CDVInvokedUrlCommand*)command {

    if(isDialogOpened == NO)
    {

        isDialogOpened = YES ;

     CDVbcsProcessor* processor;
    NSString*       callback;
    NSString*       capabilityError;

    callback = command.callbackId;

    // We allow the user to define an alternate xib file for loading the overlay.
    NSString *overlayXib = nil;
    if ( [command.arguments count] >= 1 )
    {
        overlayXib = [command.arguments objectAtIndex:0];
    }

    capabilityError = [self isScanNotPossible];
    if (capabilityError) {
        [self returnError:capabilityError callback:callback];
        return;
    }

    processor = [[CDVbcsProcessor alloc]
                 initWithPlugin:self
                 callback:callback
                 parentViewController:self.viewController
                 alterateOverlayXib:overlayXib
                 ];
    // queue [processor scanBarcode] to run on the event loop
    [processor performSelector:@selector(scanBarcode) withObject:nil afterDelay:0];
    }

}

then add this isDialogOpened = NO ; at the end of these functions : barcodeScanDone, barcodeScanSucceeded , barcodeScanFailed , the issue on my case it was that the scan process was initialized multiple times something like when you fast press two times scan button don't know if this help someone but for me works well with this change i'm sure is not the best one but at less i fix it.

softmixt avatar Jan 11 '16 12:01 softmixt