在 Ionic 中调用 Pdf417 phonegap/cordova 插件
Calling Pdf417 phonegap/cordova plugin in Ionic
我无法在 Ionic 应用程序的演示模式下成功调用 Pdf417 phonegap/cordova plugin 扫描功能。我正在 iOS.
上使用 Ionic View 测试插件
Here is a linked Github repository 包含只有一个状态和控制器的应用程序的简化版本。
不幸的是,我完全不明白为什么这不起作用
当我测试它时。我收到一条错误消息 'cordova is not defined'
在浏览器中,我希望这是因为 cordova 插件应该
404 在浏览器中,但在 Ionic View 中也不起作用。
在尝试完成这项工作之前,我已经使用 'cordova plugin add (location of pdf417 git repo') 成功安装了插件。
如有任何帮助,我们将不胜感激。我没有太多经验
所以总的来说我可能走错了路,如果我走错了,请提前道歉。任何指导都会有所帮助。如果我不清楚任何事情,我会很乐意详细说明。我确定我可能遗漏了一些需要的信息。
这是我的 app.js 应用程序:
angular.module('app', ['ionic'])
/**
* RUN
*/
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
/**
* CONTROLLERS
*/
//Workflow Controller
.controller('workflowCtrl', ['$scope', '$ionicPlatform', '$ionicPopup',
function($scope, $ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
//***PDF417 SCANNER***
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
}
var types = ["PDF417", "QR Code"];
var options = {
beep : true, // Beep on
noDialog : true,
uncertain : false, //Recommended
quietZone : false, //Recommended
highRes : false, //Recommended
inverseScanning: false,
frontFace : false
};
var licenseiOs = null;
var licenseAndroid = null;
$scope.barcodeResult;
$scope.fields;
$scope.scan = function() {
$ionicPopup.alert({
title:'Scan Button Clicks',
});
console.log('Scan Button Clicks');
cordova.plugins.pdf417Scanner.scan(
// Register the callback handler
function callback(scanningResult) {
// handle cancelled scanning
if (scanningResult.cancelled == true) {
console.log('Scanner cancelled');
$scope.warnings = "Cancelled";
return;
}
// Obtain list of recognizer results
var resultList = scanningResult.resultList;
// Iterate through all results
for (var i = 0; i < resultList.length; i++) {
// Get individual resilt
var recognizerResult = resultList[i];
if (recognizerResult.resultType == "Barcode result") {
// handle Barcode scanning result
if (typeof(recognizerResult.raw) != "undefined" && recognizerResult.raw != null) {
var raw = hex2a(recognizerResult.raw);
}
$scope.barcodeResult = {
"Data": recognizerResult.data,
"Raw": raw,
"Type": recognizerResult.type
};
} else if (recognizerResult.resultType == "USDL result") {
// handle USDL parsing result
var fields = recognizerResult.fields;
$scope.fields = {
/** Personal information */
"USDL version": fields[kPPAamvaVersionNumber],
"Family name": fields[kPPCustomerFamilyName],
"First name": fields[kPPCustomerFirstName],
"Date of birth": fields[kPPDateOfBirth],
"Sex": fields[kPPSex],
"Eye color": fields[kPPEyeColor],
"Height": fields[kPPHeight],
"Street": fields[kPPAddressStreet],
"City": fields[kPPAddressCity],
"Jurisdiction": fields[kPPAddressJurisdictionCode],
"Postal code": fields[kPPAddressPostalCode],
/** License information */
"Issue date": fields[kPPDocumentIssueDate],
"Expiration date": fields[kPPDocumentExpirationDate],
"Issuer ID": fields[kPPIssuerIdentificationNumber],
"Jurisdiction version": fields[kPPJurisdictionVersionNumber],
"Vehicle class": fields[kPPJurisdictionVehicleClass],
"Restrictions": fields[kPPJurisdictionRestrictionCodes],
"Endorsments": fields[kPPJurisdictionEndorsementCodes],
"Customer ID": fields[kPPCustomerIdNumber]
};
}
}
},
// Register the error callback
function errorHandler(err) {
console.log("error: " + err);
$scope.warnings = err;
},
types, options, licenseiOs, licenseAndroid
);
};
//***END PDF417 SCANNER***
});
}])
/**
* ROUTING
*/
.config(function($ionicConfigProvider, $stateProvider, $urlRouterProvider)
{
$ionicConfigProvider.tabs.position('bottom');
$ionicConfigProvider.tabs.style('striped');
$ionicConfigProvider.navBar.alignTitle('center');
$urlRouterProvider.otherwise('/tab/workflow');
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'partials/tab.html'
})
// Each tab has its own nav history stack:
.state('tab.workflow', {
url: '/workflow',
views: {
'tab-workflow': {
templateUrl: 'partials/tab-workflow.html',
controller: 'workflowCtrl'
}
}
})
});
此外,这是我点击按钮启动 pdf417 时的系统日志 'ionic emulate ios' 到 运行 模拟器。
THREAD WARNING: [‘Pdf416Scanner’] took ’12.760742’ ms.
Plugin should use a background thread.
更新:这个错误是预期的,因为外围设备在模拟器中不可用,虽然我在离子视图中测试时仍然没有任何功能(目前使用iOS)。
你的问题的答案很简单:Ionic View 只支持有限数量的插件(目前),你的不在列表中。
一开始支持的更少,但后来增加了更多。
这是相关的 link:http://docs.ionic.io/v1.0/docs/view-usage
我建议通过 USB 部署到设备。
我无法在 Ionic 应用程序的演示模式下成功调用 Pdf417 phonegap/cordova plugin 扫描功能。我正在 iOS.
上使用 Ionic View 测试插件Here is a linked Github repository 包含只有一个状态和控制器的应用程序的简化版本。
不幸的是,我完全不明白为什么这不起作用 当我测试它时。我收到一条错误消息 'cordova is not defined' 在浏览器中,我希望这是因为 cordova 插件应该 404 在浏览器中,但在 Ionic View 中也不起作用。
在尝试完成这项工作之前,我已经使用 'cordova plugin add (location of pdf417 git repo') 成功安装了插件。
如有任何帮助,我们将不胜感激。我没有太多经验 所以总的来说我可能走错了路,如果我走错了,请提前道歉。任何指导都会有所帮助。如果我不清楚任何事情,我会很乐意详细说明。我确定我可能遗漏了一些需要的信息。
这是我的 app.js 应用程序:
angular.module('app', ['ionic'])
/**
* RUN
*/
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
/**
* CONTROLLERS
*/
//Workflow Controller
.controller('workflowCtrl', ['$scope', '$ionicPlatform', '$ionicPopup',
function($scope, $ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
//***PDF417 SCANNER***
function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
}
var types = ["PDF417", "QR Code"];
var options = {
beep : true, // Beep on
noDialog : true,
uncertain : false, //Recommended
quietZone : false, //Recommended
highRes : false, //Recommended
inverseScanning: false,
frontFace : false
};
var licenseiOs = null;
var licenseAndroid = null;
$scope.barcodeResult;
$scope.fields;
$scope.scan = function() {
$ionicPopup.alert({
title:'Scan Button Clicks',
});
console.log('Scan Button Clicks');
cordova.plugins.pdf417Scanner.scan(
// Register the callback handler
function callback(scanningResult) {
// handle cancelled scanning
if (scanningResult.cancelled == true) {
console.log('Scanner cancelled');
$scope.warnings = "Cancelled";
return;
}
// Obtain list of recognizer results
var resultList = scanningResult.resultList;
// Iterate through all results
for (var i = 0; i < resultList.length; i++) {
// Get individual resilt
var recognizerResult = resultList[i];
if (recognizerResult.resultType == "Barcode result") {
// handle Barcode scanning result
if (typeof(recognizerResult.raw) != "undefined" && recognizerResult.raw != null) {
var raw = hex2a(recognizerResult.raw);
}
$scope.barcodeResult = {
"Data": recognizerResult.data,
"Raw": raw,
"Type": recognizerResult.type
};
} else if (recognizerResult.resultType == "USDL result") {
// handle USDL parsing result
var fields = recognizerResult.fields;
$scope.fields = {
/** Personal information */
"USDL version": fields[kPPAamvaVersionNumber],
"Family name": fields[kPPCustomerFamilyName],
"First name": fields[kPPCustomerFirstName],
"Date of birth": fields[kPPDateOfBirth],
"Sex": fields[kPPSex],
"Eye color": fields[kPPEyeColor],
"Height": fields[kPPHeight],
"Street": fields[kPPAddressStreet],
"City": fields[kPPAddressCity],
"Jurisdiction": fields[kPPAddressJurisdictionCode],
"Postal code": fields[kPPAddressPostalCode],
/** License information */
"Issue date": fields[kPPDocumentIssueDate],
"Expiration date": fields[kPPDocumentExpirationDate],
"Issuer ID": fields[kPPIssuerIdentificationNumber],
"Jurisdiction version": fields[kPPJurisdictionVersionNumber],
"Vehicle class": fields[kPPJurisdictionVehicleClass],
"Restrictions": fields[kPPJurisdictionRestrictionCodes],
"Endorsments": fields[kPPJurisdictionEndorsementCodes],
"Customer ID": fields[kPPCustomerIdNumber]
};
}
}
},
// Register the error callback
function errorHandler(err) {
console.log("error: " + err);
$scope.warnings = err;
},
types, options, licenseiOs, licenseAndroid
);
};
//***END PDF417 SCANNER***
});
}])
/**
* ROUTING
*/
.config(function($ionicConfigProvider, $stateProvider, $urlRouterProvider)
{
$ionicConfigProvider.tabs.position('bottom');
$ionicConfigProvider.tabs.style('striped');
$ionicConfigProvider.navBar.alignTitle('center');
$urlRouterProvider.otherwise('/tab/workflow');
$stateProvider
// setup an abstract state for the tabs directive
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'partials/tab.html'
})
// Each tab has its own nav history stack:
.state('tab.workflow', {
url: '/workflow',
views: {
'tab-workflow': {
templateUrl: 'partials/tab-workflow.html',
controller: 'workflowCtrl'
}
}
})
});
此外,这是我点击按钮启动 pdf417 时的系统日志 'ionic emulate ios' 到 运行 模拟器。
THREAD WARNING: [‘Pdf416Scanner’] took ’12.760742’ ms.
Plugin should use a background thread.
更新:这个错误是预期的,因为外围设备在模拟器中不可用,虽然我在离子视图中测试时仍然没有任何功能(目前使用iOS)。
你的问题的答案很简单:Ionic View 只支持有限数量的插件(目前),你的不在列表中。
一开始支持的更少,但后来增加了更多。
这是相关的 link:http://docs.ionic.io/v1.0/docs/view-usage
我建议通过 USB 部署到设备。