本文整理汇总了TypeScript中@ionic-native/barcode-scanner.BarcodeScanner类的典型用法代码示例。如果您正苦于以下问题:TypeScript BarcodeScanner类的具体用法?TypeScript BarcodeScanner怎么用?TypeScript BarcodeScanner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BarcodeScanner类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: scanQrCode
scanQrCode() {
this.barcodeScanner.scan( ).then((barcodeData) => {
if(barcodeData.cancelled || barcodeData.format !== 'QR_CODE') {
return;
}
const regex = /kraken:\/\/apikey\?key=(.*?)&secret=(.*)/i;
// let m = regex.exec(barcodeData.text);
let output = regex.exec(barcodeData.text);
if(output) {
this.apiKey = output[1];
this.privateKey = output[2];
}
this.apiKeyChanged();
this.privateKeyChanged();
}, (err) => {
this._displayAlert(err);
});
}
示例2: scan
/***
* 调用二维码扫描
* @returns {{codeData: string}}
*/
scan() {
return this.barcodeScanner.scan();
// this.barcodeScanner.scan().then(barcodeData => {
// Fun(browserDetection);
// }).catch(err => {
// errorFun(err);
// });
// return {
// codeData: 'EehM1A6MnVZxs6qH8AEA1pSLeW4RxmqhuU'
// };
}
示例3:
scanCode() {
this.barcode.scan().then((barcodeData) => {
let data = JSON.parse(barcodeData.text);
this.api.data.url = data.url + "/";
this.api.data.username = data.username;
this.api.data.password = "";
this.api.token = data.token;
this.api.storage.set("token", data.token);
this.doLogin();
}, (err) => {
this.alert.create({ title: "Oops", subTitle: "Ocurrió un error " + err, buttons: ["Ok"] }).present();
});
}
示例4: scanQR
public scanQR() {
this.buttonText = "Loading..";
this.loading = true;
this._barcodeScanner.scan().then((barcodeData) => {
if (barcodeData.cancelled) {
console.log("User cancelled the action!");
this.buttonText = "Scan";
this.loading = false;
return false;
}
console.log("Scanned successfully!");
console.log(barcodeData);
this.goToResult(barcodeData);
}, (err) => {
console.log(err);
});
}
示例5:
handler: () => {
this.barcodeScanner.scan().then((barcodeData) => {
this.user.accesstoken = barcodeData.text;
this.userService.PostAccessToken({ accesstoken: this.user.accesstoken }).subscribe((data) => {
if (data.success) {
this.user.loginname = data.loginname;
this.user.avatar_url = data.avatar_url;
this.events.publish('user', this.user);
this.storage.set('user', this.user);
this.navCtrl.push(AccountPage).then(() => {
let index = this.viewCtrl.index;
this.navCtrl.remove(index);
});
this.utilService.toast('登录成功');
}
else {
this.utilService.toast('登录失败');
}
})
}, (err) => {
this.alertCtrl.create({
title: '注意',
message: '在非手机设备(浏览器)时登录,需填入相关用户信息,必填!',
inputs: [
{
name: 'loginname',
placeholder: '用户名'
},
{
name: 'avatar_url',
placeholder: '头像URL',
},
{
name: 'accesstoken',
placeholder: 'accesstoken',
}
],
buttons: [
{
text: '取消',
role: 'cancel',
handler: data => {
}
},
{
text: '登录',
handler: data => {
if (data.loginname && data.avatar_url && data.accesstoken) {
this.user.loginname = data.loginname;
this.user.avatar_url = data.avatar_url;
this.user.accesstoken = data.accesstoken;
this.events.publish('user', this.user);
this.storage.set('user', this.user);
this.navCtrl.push(AccountPage).then(() => {
let index = this.viewCtrl.index;
this.navCtrl.remove(index);
});
} else {
return false;
}
}
}
]
}).present();
console.log(err);
});
}