本文整理匯總了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);
});
}