don/ionic-nfc-reader

Scan nfc the first time, app doesn't get the nfc message. But then scan again, I can got the msg.

alexniver opened this issue · 4 comments

Hi, I use ionic and use your code, when the app starts , I scan nfc, my phone give other app options to scan nfc and my app got nothing. I cancel the options then scan again, my app got the nfc message right. How can I make the app get the nfc message at the first time? where did I do wrong? I see nothing special in your config.xml or some where other place. Could you help me? Thank you very much.

I run your app, goes well. Seems that I have got some wrong step.

I finally find where I went wrong.

in my app.js, $cordovaNetwork.getNetwork(); and $cordovaNetwork.isOnline() made this issue.

I don't know if this is a bug. Just share my experience

.run(function($ionicPlatform, AuthService, Constants, $state, $rootScope, $http, $cordovaNetwork, $ionicLoading) {
    $ionicPlatform.ready(function() {
        // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
        // for form inputs)
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }

        //these code will made nfc not work so well, don't use these code again
        /*if(Constants.DEBUGMODE){
            var networkType = $cordovaNetwork.getNetwork();
            console.log("Network used on this machine : "+networkType);
        }


        if(!$cordovaNetwork.isOnline()){
            if(Constants.DEBUGMODE){
                console.log("No NETWORK FOUND");
                // at this point we need to broadcast a no network found event and the app.controller will get that and display the popup
                $rootScope.$broadcast('event:app-networkRequired');
            }
        }else{
            if(Constants.DEBUGMODE){
                console.log("NETWORK FOUND");
            }
        }*/



    });
don commented

@alexniver I'm not sure why those constants broke the NFC scanning. You're original problem sounds like an initialization issue, usually solved by $ionicPlatform.ready. Initialization of the plugin is a bit screwy. If you find a better solution, please let me know.