Phonegap-plugin-barcodescanner: App crashes on iOS 10 permission dialog --> undefined

Created on 20 Sep 2016  路  21Comments  路  Source: phonegap/phonegap-plugin-barcodescanner

Expected Behaviour

Request permission for camera and open the camera

Actual Behaviour

First time launch iOS aks for permisson. But the Dialog shows a new undefined string which was not there in iOS 9. The error that the device has no access to the camera fires and it's not possible at all cost to start the camera until you kill the app and fire the camera again. Then everthing works fine. The permission to use the camera doesn't work on iOS 10.0.

Reproduce Scenario (including but not limited to)

cordova 6.3.1
ionic 2.1.0-beta.1
OS X El Captain

Install an app with the plugin on a iOS 10 device with the following code:

$scope.scan = function() {
      $cordovaBarcodeScanner.scan().then(function(barcodeData) {
        if (barcodeData.text === "mappar1_ital") {
          save("isUnlocked", true);

          if ($state.current.name === "l1") {
            $state.go("11");
          }
          if ($state.current.name === "l2") {
            $state.go("12");
          }
        }

      }, function(error) {
        console.log(JSON.stringify(error));
      });

      function alertDismissed() {
        console.log("OK");
      }

      cordova.plugins.diagnostic.isCameraAuthorized(function(authorized) {
        if (authorized === false) {
          navigator.notification.alert(
            'Bitte aktivieren Sie den Zugriff auf die Kamera in den Einstellungen!',
            alertDismissed, // message
            'Kein Zugriff', // title
            'OK' // buttonName
          );
        }
      }, function(error) {
        console.error("The following error occurred: " + error);
      });
    }

Platform and Version

ios 10.0

Plugin version

phonegap-plugin-barcodescanner newest

Any help much appreciated!

Most helpful comment

My app was not working on iOS10 with latest phonegap barcode scanner plugin (6.0.3) until I found this post related to the CSP, which fixed it by adding the gap: to the allowed content:
http://stackoverflow.com/a/39638649/1752548

All 21 comments

Which plugin version are you using? this has been fixed

I've deinstalled the plugin and added it again with ionic plugin add phonegap-plugin-barcodescanner Should i use git instead?

Now i've installed the plugin withionic plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner Still an issue.

Are you getting version 6.0.2?
That's the one with the fix

To check the version use ionic plugin list

phonegap-plugin-barcodescanner 6.0.2 "BarcodeScanner"

Yes, 6.0.2

The app being blocked is probably because the app ask for the permission and you show your alert over it, don't do it. The plugin will check if the permission is set or not and show a message.

But the "undefined" string shouldn't be shown, it should be an empty string

Thank you! Can you tell me how I can remove the undefined in the permission alert? We will go into production in 5 days =)

You can install with
ionic plugin add phonegap-plugin-barcodescanner --variable CAMERA_USAGE_DESCRIPTION="the reason you want to give to scan barcodes" or ionic plugin add phonegap-plugin-barcodescanner --variable CAMERA_USAGE_DESCRIPTION=" "

I experienced a similar problem - I had to update the App to support iOS 10 (which requires a NSCameraUsageDescription), but couldn't upgrade the barcodescannerplugin from 4.x.x to V. 6.x.x, so I wrote this plugin.

NPM
cordova plugin add cordova-plugin-ios-camera-permissions --save

GutHub Repo
https://github.com/Cordobo/cordova-plugin-ios-camera-permissions

HTH

You can also install cordova-plugin-camera

cordova plugin add cordova-plugin-camera --variable CAMERA_USAGE_DESCRIPTION="the reason you want to give to scan barcodes"

@jcesarmobile True, for the latest version. Unfortunatelly I couldn't update to 6.x.x, and as it's not working with 4.2.1, I wrote this mini-plugin. Maybe others are stuck with a certain plugin version as well, so it might help.

PS: I even tried this install routine with the flag --variable on 4.x.x but with no success :)
PPS: Arrgh, you mentioned cordova-plugin-camera ... my fault :(

Is there any reason why permissions alert doesn't show up promptly? I'm testing on iOS 10 now and it's very frustrating.

edit: Actually the permission pop-ups doesn't appear sequentially now. I'm requesting for Push Notification, Location, Camera, Photo Library.

@jcuervo here they come up the first time the app requests the permissions. Maybe you can trigger them in the first view/controller.

I'll try it out. Thanks, buddy!

@Cordobo I mean't installing the camera plugin instead of updating the barcode plugin

@jcuervo the permissions should appear when you are going to use that permission

@jcesarmobile i can now use the barcode scanner, but I have to close the app (tap the home button) and tap the app again then the barcode scanner appears. you ever encountered this? (never had this issue on previous iOS versions)

This also happens on the Photo Library. 馃挜

I have not encountered this issue myself, but I think there is an issue open about it, usually when using phonegap build

@jcesarmobile thanks for the info! btw, is this related to the camera plugin or on cordova itself?

@jcuervo no idea

My app was not working on iOS10 with latest phonegap barcode scanner plugin (6.0.3) until I found this post related to the CSP, which fixed it by adding the gap: to the allowed content:
http://stackoverflow.com/a/39638649/1752548

@asierazaceta wow! it worked! thanks, man!

This thread has been automatically locked.

Was this page helpful?
0 / 5 - 0 ratings