I am on a windows machine using ionic framework and the android build for my android phone works great.
Then I did a build using phone gap online builder from adobe and the app itself runs, but when I try to activate the barcode scanner from within the app on my ipod touch, there is no response.
Any insight would be appreciated.
I am having this same issue on IOS. The scanner is perfectly working on android but on IOS 9.1 I am not getting any error and the button doesnt seem to be triggering anything at all. I am using the scanner to scan voucher barcodes and redeem them. I am hoping there is some answer to this problem. Safari doesn't log any error when inspecting the UIWebView, so I am unable to realise what the problem actually is.
Following is the code on my controller:
.controller('ScanCtrl', function($scope,$http, $stateParams,$cordovaBarcodeScanner,$ionicPlatform,webServer,$ionicModal) {
$scope.cardShow = false;
$scope.notification='no data available.';
$scope.closeModal = function() {
$scope.modal.hide();
};
$ionicModal.fromTemplateUrl('voucher-redemption.html', {
scope: $scope,
animation: 'slide-in-up',
}).then(function(modal) {
$scope.modal = modal;
});
$scope.redeemVoucher = function(voucherValue){
$http({
method:'POST',
url:webServer + '/wp-admin/admin-ajax.php?action=redeem-voucher',
data:'vouchervalue=' + voucherValue+ '&voucherid='+$scope.voucherId,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(response) {
// alert(firstLogin);
$scope.cardShow = true;
if(response['type'] =='error' ){
// alert(response['message']);
$scope.notification = response['message'];
$scope.notificationClass = 'assertive-bg white';
} else {
$scope.notification = 'Voucher redeemed successfully!';
$scope.notificationClass = 'balanced-bg white';
}
$scope.closeModal();
}).error(function(response){
alert(response);
});
}
document.addEventListener("deviceready", function () {
$scope.scanCode = function(){
$ionicPlatform.ready(function(){
$cordovaBarcodeScanner
.scan()
.then(function(barcodeData) {
var code = barcodeData.text;
code = parseInt(code.substring(3));
// alert(code);
$scope.voucherId = code;
var servUrl = webServer +'/wp-admin/admin-ajax.php?action=voucher-details';
$http.get(servUrl+'&voucherid='+code).success(function(response){
$scope.cardShow = true;
if(response['type'] =='error'){
$scope.notification = response['message'];
$scope.notificationClass = 'assertive-bg white';
} else {
// alert(response);
if(response['redeemable_value'] == 0){
$scope.notification = 'We are sorry but this voucher has been already redeemed. Please try a different voucher.';
$scope.notificationClass = 'assertive-bg white';
}else {
$scope.optionsArray = $scope.getRedemptionOptions(response['redeemable_value']);
$scope.cardShow = false;
$scope.modal.show();
}
}
});
}, function(error) {
alert('error');// An error occurred
});
});
}
}, false);
})
I can scan a barcode from an Iphone 6 and an Ipad, however on an Ipod touch, it activates the camera for the first frame, and freezes.
On Xcode I have the following error:
Warning: Attempt to present <CDVbcsViewController: 0x15f30c400> on <MainViewController: 0x15dd4fab0> whose view is not in the window hierarchy!
my code is just the example:
$scope.scanBarcode = function() {
$cordovaBarcodeScanner.scan().then(function(imageData) {
alert(imageData.text, imageData);
console.log("Barcode Format -> " + imageData.format);
}, function(error) {
console.log("An error happened -> " + error);
});
};
We switch to another plugin, works perfectly on iOS9 (not tested with Android or Windows).
Also launches faster than the phonegap one.
Had same problem and found a fix here: https://github.com/phonegap/phonegap-plugin-barcodescanner/issues/30
This is an older issue, but one i have seen many times as part of working with ionic. The real issue is that for some reason the action that launches the scanner is detected as executed twice, causing 2 instances of the scanner plugin to launch. Only one can access the camera at a time, so you may only get the first frame on the instance you can see.
It's fairly easy to get around this by doing a simple check if the function was already executed. Once the promise is returned by the plugin, the flag is reset.
The code below demonstrates this, and as an added feature it doesn't try to launch the scanner in a development browser, and instead returns an alert.
https://gist.github.com/AlexSwensen/3a3b0dd6797d3ffe7d63
This example I have used several times in the Ionic IRC and Slack channels. This is not an issue with the plugin and should be closed.
Hi Alex,
I tried the workaround you proposed. there's no change in the behavior of the plug-in. The problem I'm seeing is that it works well with an iPhone 5 but it doesn't with an iPad2.
I wonder how much this plug-in has been tested by the developers :-(
I can confirm that i have not had any trouble with this scanner after implementing my proposed workaround. I am testing on multiple models of iPhone, and an iPad Air 2. Check the XCode debug log for clues.
I'm not using Ionic, and also see this issue on iOS (simple HTML and jQuery app), so probably more of an issue of it loading twice rather than Ionic specific.
Added the logic to prevent the scanner from being launched twice and fixed the iOS freezing issue for me. The scanner was basically unusable on iOS until I found this. I am using Ionic with ngCordova.
This thread has been automatically locked.
Most helpful comment
This is an older issue, but one i have seen many times as part of working with ionic. The real issue is that for some reason the action that launches the scanner is detected as executed twice, causing 2 instances of the scanner plugin to launch. Only one can access the camera at a time, so you may only get the first frame on the instance you can see.
It's fairly easy to get around this by doing a simple check if the function was already executed. Once the promise is returned by the plugin, the flag is reset.
The code below demonstrates this, and as an added feature it doesn't try to launch the scanner in a development browser, and instead returns an alert.
https://gist.github.com/AlexSwensen/3a3b0dd6797d3ffe7d63
This example I have used several times in the Ionic IRC and Slack channels. This is not an issue with the plugin and should be closed.