-2

Please help me about ngCordova-nfc (by using phonegap-nfc). I have a cordova project (no ionic/phonegap). I want to read NFC tag id by using this code. But I can't. Can you help me?

angular.module('app')
    .controller('AppCtrl', ['$scope', '$translate', '$localStorage', '$window', '$cordovaNfc', '$cordovaNfcUtil',
      function(              $scope,   $translate,   $localStorage,   $window, $cordovaNfc, $cordovaNfcUtil ) {

    // NFC
      //alert("Out of NFC");

      $cordovaNfc.then(function(nfcInstance){

            //Use the plugins interface as you go, in a more "angular" way
            nfcInstance.addNdefListener(function(event){
                //Callback when ndef got triggered
                var tag = JSON.stringify(event.tag);

                if (tag.serialNumber) {
                  $scope.tagid = tag.serialNumber;
                  tag.isWritable = !tag.isLocked;
                  tag.canMakeReadOnly = tag.isLockable;
                  alert("Hello"+$scope.tagid);
                }

              })
            .then(
            //Success callback
            function(event){
              alert("bound success");
            },
            //Fail callback
            function(err){
              alert("error");
            });
          });

      $cordovaNfcUtil.then(function(nfcUtil){
        alert( nfcUtil.bytesToString("some bytes") );
      });
  • Hello unliker, Can you explain why down mark (-1) on my this question? – Munia Zaman Apr 18 '17 at 21:23
  • Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example. – LaurentY Apr 19 '17 at 07:26
  • Thanks. I am new here & it's my first question. – Munia Zaman Apr 20 '17 at 13:20

1 Answers1

0

Did You try whether your device is nfc supported or not ? and check if nfc is disabled ?? by the following piece of code.

nfc.enabled(
  function() {alert('yes!')},
  // msg is one of NO_NFC (no hardware support) or NFC_DISABLED (supported but disabled)
  function(msg) {alert(msg)}
);

And Post the errors you got. Hope it helps you

Naresh Kumar
  • 932
  • 5
  • 12