valentiniljaz / cordova-nfcv-plugin

Cordova plugin for reading and writing to NFC tags using NfcV protocol (with support for Ionic2)
14 stars 9 forks source link

ReferenceError: NfcV is not defined ReferenceError: NfcV is not defined #10

Closed UnrizaC closed 5 years ago

UnrizaC commented 5 years ago

Hello,

We are currently developing an Android app with ionic 3. For this app, we need to read information and send commands (with transceive method) to a medical device through NFC. We use your plugin, however, we didn't manage to read any data nor even a tag. We based our code on the examples you gave in this issue. Our device uses NfcV and NdefFormatable technology Our environment is:

ionic info

cli packages: (/usr/local/lib/node_modules)

    @ionic/cli-utils  : 1.19.1
    ionic (Ionic CLI) : 3.19.1

global packages:

    cordova (Cordova CLI) : 8.0.0 

local packages:

    @ionic/app-scripts : 3.1.8
    Cordova Platforms  : android 7.0.0
    Ionic Framework    : ionic-angular 3.9.2

System:

    Android SDK Tools : 26.1.1
    Node              : v9.8.0
    npm               : 5.6.0 
    OS                : Linux 4.15

Environment Variables:

    ANDROID_HOME : /opt/android-sdk-linux

Misc:

    backend : pro

We try to run the basic example you gave in this discussion but we have some errors. Furthermore, we read that AndroidManifest.xml needs some modification but we didn't manage to modify it correctly. We tried to add modifications to platforms/android/android.json and to platforms/android/app/src/main/AndroidManifest.xml but neither worked.

This is our code:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { NFC, Ndef } from "@ionic-native/nfc";
import { Platform } from 'ionic-angular';
import { NfcvService } from 'cordova-nfcv-plugin/ionic2';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';

@IonicPage()
@Component({
  selector: 'page-nf-cv-test',
  templateUrl: 'nf-cv-test.html',
})

export class NFCvTestPage {
  public tag;

  constructor(
    statusBar: StatusBar, 
    splashScreen: SplashScreen,
    platform : Platform,
    public navCtrl: NavController,
    public navParams: NavParams,
    public nfcvService: NfcvService,
    public nfc: NFC,
    public NDdef: Ndef,
  ) {
    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();
      this.nfcvService.waitForNdef();
    });

  }

  ionViewDidLoad() {
    console.log("in ionViewDidLoad");
    this.nfcvService.onTag(
      (tag) => {
        console.log('Found tag', tag);
          this.nfcvService
          .getSystemInfo(false)
          .then((systemInfo) => {
              console.log('SystemInfo:', systemInfo); 
               this.nfcvService.waitForTag();   
          })
          .catch((error) => {
              console.log('Error reading:', error);
              this.nfcvService.waitForTag();
          });;
    },
    (error) => {
        console.log('Error on tag', error);
        this.nfcvService.waitForTag();
    });
  }
 }

We have this error even if the device is not near the phone The error we have:

vendor.js:1822 ERROR Error: Uncaught (in promise): ReferenceError: NfcV is not defined
ReferenceError: NfcV is not defined
    at NfcvService.waitForNdef (vendor.js:144310)
    at main.js:1022
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (vendor.js:5123)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (vendor.js:5114)
    at t.invokeTask (polyfills.js:3)
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (vendor.js:5114)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)
    at e.invokeTask [as invoke] (polyfills.js:3)
    at p (polyfills.js:2)
    at HTMLAnchorElement.v (polyfills.js:2)

vendor.js:141115 Error loading deploy information. TypeError: Cannot read property 'deploy' of undefined
    at vendor.js:141115
    at new t (polyfills.js:3)
    at Deploy.<anonymous> (vendor.js:141115)
    at step (vendor.js:141115)
    at Object.next (vendor.js:141115)
    at fulfilled (vendor.js:141115)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)

Could you please help us to identify what are we doing wrong, and how to modify the AndroidManifest properly?

Thank you very much in advance!

valentiniljaz commented 5 years ago

Hi,

thank you for using my plugin.

According to your error report it looks like there is an issue with the installation. "NfcV is not defined" seems like an error with Ionic plugin installation. Did you run the following commands:

ionic plugin add https://github.com/valentiniljaz/cordova-nfcv-plugin
npm install https://github.com/valentiniljaz/cordova-nfcv-plugin

Hope it helps.