首次NFC读取不起作用

时间:2017-07-24 19:34:30

标签: ionic2 nfc

我必须阅读带有离子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);
  }));
}

我不知道发生了什么,有人可以帮助我吗?

0 个答案:

没有答案