chariotsolutions / phonegap-nfc

PhoneGap NFC Plugin
MIT License
706 stars 556 forks source link

Example code fails in 'hello world' #292

Closed richardjohns closed 6 years ago

richardjohns commented 6 years ago

Hi there,

Trying to get up and running with nfc alongside the helpful book resource... appreciate any help with this basic installation question - when using the readme example code in a new phonegap 'hello world' project, it returns 'function nfc not defined' ie I'm not getting access to the plugin despite including it via 'phonegap plugin add phonegap-nfc' command.

For nfc.addNdefListener when I hover over with the vscode linter it shows - 'var nfc: PhoneGapNfc.Nfc', so thinking that the link to the plugin can be seen by vscode and probably correct, but for some reason when loaded in the browser or on the phone, the link isn't being recognised.

To work around this I included an html script tag linking to the phonegap-nfc.js (alongside index.js), however it now returns 'NFC reader failed to initialise "Missing command error" on both browser and android platforms.

Now thinking that the phonegap android app after loading project is not getting access to my phone's nfc hardware.

Best, Richard

don commented 6 years ago

Can you provide a link to the instructions you're following?

NFC apps will fail in the browser and emulator they must be run on a real device with NFC.

You should let Cordova include the JavaScript and HTML. See https://github.com/chariotsolutions/phonegap-nfc/issues/293#issuecomment-338704716