konstantinkrassmann / ngCordova-nfc

Wrapper for the NFC functionality
MIT License
11 stars 4 forks source link

Example for Corodva, Angularjs project (No Ionic/PhoneGap) #11

Open MuniaZaman opened 7 years ago

MuniaZaman commented 7 years ago

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? My controller code is here...

` 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") );
  });`
konstantinkrassmann commented 7 years ago

Refer to https://github.com/chariotsolutions/phonegap-nfc

Do you hear a sound of the device recognizing the nfc tag ?

MuniaZaman commented 7 years ago

Thanks for replay. Yes, there is a sound of the device recognizing the NFC tag. But "alert" window is not showing. I am using mobile Xiaomi Mi5. NFC option is enabled & allow for my app as well. There is no any error in my browser console or mobile device. Thanks.

pradipta007 commented 5 years ago

Do anyone have solution to the above mentioned problem??