我必须阅读带有离子2的NFC标签,问题是第一次尝试不读,如果我再次阅读工作正常。我在platform.ready()中初始化nfc监听器我认为这应该足够了......
这是我的代码:
@IonicPage()
@Component({
selector: 'page-dispositivo',
templateUrl: 'dispositivo.html',
providers: [NFC, Ndef, Diagnostic, Vibration]
})
export class DispositivoPage {
subscriptions: Array<Subscription> = new Array<Subscription>();
constructor(
public navCtrl: NavController,
public navParams: NavParams,
private auth: AuthService,
public loading: LoadingController,
public alertCtrl: AlertController,
public toastCtrl: ToastController,
private nfc: NFC,
private ndef: Ndef,
public diagnostic: Diagnostic,
public platform: Platform,
public vibration: Vibration
) {
platform.ready().then(() => {
this.initNFC();
});
}
initNFC() {
this.nfc.enabled()
.then(() => {
this.addListenNFC();
}).catch(err => {
let alert = this.alertCtrl.create({
subTitle: 'Active la conexión NFC para para leer artículos',
buttons: [
{
text: 'Activar más tarde',
handler: () => {
this.goToHome();
}
},
{
text: 'Ir a Ajustes para activar',
handler: () => {
this.nfc.showSettings().then(rs => {
this.goToHome();
});
}
}]
});
alert.present();
});
}
addListenNFC() {
this.subscriptions.push(this.nfc.addTagDiscoveredListener().subscribe(nfcData => {
this.processResponse(nfcData);
}));
}
我不知道发生了什么,有人可以帮助我吗?