konstantinkrassmann / ngCordova-nfc

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

Can't see nfcInstance.addTagDiscoveredListener event fired #2

Closed gerbil closed 9 years ago

gerbil commented 9 years ago

I got Ionic + ngCordova project. So i can't see anything except 'ready' and 'ok' alerts..

My app.js:

angular.module('starter', ['ionic', 'ngCordova', 'ngCordova.plugins.nfc'])

    .controller('MainController', function ($scope, $cordovaNfc) {

        //Because of the problem about the async-ness of the nfc plugin, we need to wait
        //for it to be ready.
        $cordovaNfc.then(function (nfcInstance) {

            alert('ready!');

            //Use the plugins interface as you go, in a more "angular" way
            nfcInstance.addTagDiscoveredListener(function (event) {
                //Callback when ndef got triggered
            })
                .then(
                //Success callback
                function (event) {
                    alert(event);
                },
                //Fail callback
                function (err) {
                    alert(err);
                });
        });

    })

My index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <title></title>

    <!-- build:css styles/vendor.css -->
    <!-- bower:css -->
    <link rel="stylesheet" href="bower_components/ionic/release/css/ionic.css" />
    <!-- endbower -->
    <!-- endbuild -->
    <link href="styles/style.css" rel="stylesheet">

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
    <link href="styles/ionic.app.css" rel="stylesheet">
    -->

    <!-- ionic/angularjs js -->
    <!-- build:js scripts/vendor.js -->
    <!-- bower:js -->
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-animate/angular-animate.js"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
    <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="bower_components/ionic/release/js/ionic.js"></script>
    <script src="bower_components/ionic/release/js/ionic-angular.js"></script>
    <script src="bower_components/ngCordova/dist/ng-cordova.js"></script>
    <script src="bower_components/ngCordova-nfc/nfc.js"></script>
    <!-- endbower -->
    <!-- endbuild -->

    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>

    <!-- your app's js -->
    <!-- build:js scripts/scripts.js -->
    <script src="scripts/app.js"></script>
    <script src="scripts/configuration.js"></script>
    <!-- endbuild -->
</head>
<body ng-app="starter">

</body>
</html>
konstantinkrassmann commented 9 years ago

Hi,

Did your device support nfc ? Does the scanned tag work on other devices ?

Basically this ngCordova plugin is just wrapping the basic functionality.

addTagDiscoveredListener: function(callback)
                    {
                        var q = $q.defer();

                        if(typeof nfc != "undefined")
                        {
                            nfc.addTagDiscoveredListener(callback, q.resolve, q.reject);
                        }else
                            q.reject("nfc plugin not defined");

                        return q.promise;
                    },

So if it does not work, it does not fail here. Maybe check the cordova nfc plugin repository.