Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70757

Ionic 4 Nfc not reading

$
0
0

@Shadifong wrote:

So I’ve been trying to make an NFC reader, I’ve tried every example on the internet and nothing seeems to be working, this is my code right now, the nfc listener starts but it doesn’t read anything, i tried 10 other nfc reading apps and my nfc works perfcetely, the permisson is also 100% enabled for my ionic app and it does say that it’ll read nfc when i open it, but it never reads anything.
the console log works inside the platform.ready and that the listner is ready, but the .subcribe it doesn’t even enter it and it doesn’t read anything, i also added ndef and NFC as providers in app.module/.ts
I’ll really appreciate any help

import { Component } from "@angular/core";
import { NFC, Ndef } from "@ionic-native/nfc/ngx";
import {
  NavController,
  Platform,
  AlertController,
  ToastController
} from "@ionic/angular";

@Component({
  selector: "app-home",
  templateUrl: "home.page.html",
  styleUrls: ["home.page.scss"]
})
export class HomePage {
  tagId: string;
  scanned;
  granted;

  constructor(
    private nfc: NFC,
    private ndef: Ndef,
    private platform: Platform
  ) {
    this.platform.ready().then(() => {
      this.addListenNFC();
    });
  }
  addListenNFC() {
    this.nfc
      .addNdefListener(
        () => {
          console.log("successfully attached ndef listener");
        },
        err => {
          console.log("error attaching ndef listener", err);
        }
      )
      .subscribe(event => {
        console.log("received ndef message. the tag contains: ", event.tag);
        console.log("decoded tag id", this.nfc.bytesToHexString(event.tag.id));

        let message = this.ndef.textRecord("Hello world");
        this.nfc
          .share([message])
          .then()
          .catch();
      });
  }
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70757

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>