NDEF_PUSH_DISABLED (ionic 3)

#1

I am trying to share data between 2 devices using ionic NFC plugin. By using below code:

this.platform.ready().then(() => {
  console.log("platform.ready() success");
  this.nfc.share([this.ndef.textRecord('Hello world')]).then( data =>{
    console.log("Success");
  },
  err => {
    console.log("error: ", err);
  });
},
err => {
  console.log('platform.ready(): ', err);
});

After the NfcPlugin Initialized I am getting this error:
NDEF_PUSH_DISABLED

Can any one guide me how to sort out this issue?

#2

Seems like your plugin folder is corrupt + is that your first build for a real device ?

What I would do is to remove the plugins and platforms folder completly and try to build it again like that.

  • Remove the plugins and platforms folder
  • Connect your Phone
  • Open your Terminal in your Apps folder
  • Type into the Terminal ionic cordova run android

It then will ask you if you want to rebuild your platforms and plugins folder. This may take a while to build up and reinstall everything… After that the App should work on your device just fine.

If it doesn’t please provide me your ionic info and when exactly the problem occured.


Good luck :four_leaf_clover:

#3

Hello,
thank you for the response. No its not my first build on real device.

I have run these commands in sequence:

  1. ionic cordova platform rm android
  2. ionic cordova plugin rm phonegap-nfc
  3. adb kill-server
  4. adb connect MY_PHONE_IP
  5. adb devices
  6. ionic cordova plugin add phonegap-nfc
  7. ionic cordova run android

Again same error appearing:

Forwarding debug port
Attaching to app.
The key “viewport-fit” is not recognized and ignored.
deviceready has not fired after 5 seconds.
Channel not fired: onDOMContentLoaded
Ionic Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.
Angular is running in the development mode. Call enableProdMode() to enable the production mode.
Ionic Native: deviceready event fired after 8543 ms
Initialized the NfcPlugin
nfc share error: NDEF_PUSH_DISABLED

ionic info:

:heavy_check_mark: Gathering environment info - done!

Ionic:

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.0

Cordova:

cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 5 other plugins)

System:

Android SDK Tools : 26.0.2 (/Users/USERNAME/Library/Android/sdk)
ios-deploy : 1.9.2
NodeJS : v9.3.0 (/usr/local/Cellar/node/9.3.0_1/bin/node)
npm : 5.6.0
OS : macOS Sierra
Xcode : Xcode 9.2 Build version 9C40b

HTML CODE:

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  <p>{{text}}</p>
  <button ion-button (click)="NFC()">
    NFC SHARE!
  </button>
</ion-content>

TypeScript:

import { Component } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { NFC, Ndef } from '@ionic-native/nfc';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})

export class HomePage {
  constructor(
    public navCtrl: NavController,
    public nfc: NFC,
    public ndef: Ndef,
    public platform: Platform
  ) {}

  NFC() {
    this.nfc.share([this.ndef.textRecord('Hello world')]).then( () =>{
      console.log("nfc share Success");
    },
    err => {
      console.log("nfc share error: ", err);
    });
  }

}

ALSO TRIED THIS CODE BUT GOT SAME ERROR:

NFC() {
    this.nfc.enabled().then(
      () => {
        console.log('nfc enabled successfully');
        this.nfc.share([this.ndef.textRecord('Hello world')]).then( () =>{
          console.log("nfc share Success");
        },
        err => {
          console.log("nfc share error: ", err);
        });
          }
    ).catch(
      (err) => {
        console.log('nfc enabled error: ', err);
      }
    );
}
#4

Does the App work when you aren’t using your NFC code ?

Else we could say that you didn’t installed the plugin right.

#5

Yes app is working fine I have put an alert on button click that is working fine.

#6

Okay so your plugin works fine thats great! :blush:

Try my code wich I wrote some days ago to test the NFC Plugin. I can assure you that this one is working fine.

  sendValue() {
    //Attaching the NFC Listener
    this.nfc.addNdefListener(() => {
      this.SuccessAttach();
    }, (err) => {
      this.ErrorAttach();


    }).subscribe((event) => {
      //Send the message
      let value = this.ndef.textRecord('I am going to be sent over!');
      this.nfc.share([value]);
    });
  }

  receiveValue() {
    //Attaching the NFC Listener
    this.nfc.addNdefListener(() => {
      this.SuccessAttach();
    }, (err) => {
      this.ErrorAttach();


      }).subscribe((event) => {
        let alert = this.alertCtrl.create({
          subTitle: 'RECEIVED!',
          buttons: ['Dismiss']
        });
        alert.present();
      this.receivedValue = event.tag;
    });
  }


  SuccessAttach() {
    let alert = this.alertCtrl.create({
      subTitle: 'Attached Listener',
      buttons: ['Dismiss']
    });
    alert.present();
  }
  ErrorAttach() {
    let alert = this.alertCtrl.create({
      subTitle: 'Error Attaching Listener',
      buttons: ['Dismiss']
    });
    alert.present();
  }
}

You can also try this methods wich are also working fine. (Just replace them with the methods above…)


  sendValue() {
      var value = [this.ndef.textRecord('I am going to be sent over!')];
      this.nfc.write(value);
  }


  receiveValue() {
    this.nfc.addTagDiscoveredListener(() => {
      this.SuccessAttach();
    }, (err) => {
      this.ErrorAttach();


    }).subscribe((event) => {
      let alert = this.alertCtrl.create({
        subTitle: 'RECEIVED!',
        buttons: ['Dismiss']
      });
      alert.present();
      this.receivedValue = event.tag;
    });
  }

Basicly what I am doing here is to create an NFC-Tag on the first Phone sendValue and with receiveValue I scan over it and receive my Value.

What you have todo in your HTML:
Create an ngModel to see the received value. Also buttons wich fire the methods. I think that is what you wanted in the first place.

<ion-input [(ngModel)]="receivedValue"></ion-input>

Note: This is just to test if everything is in order and works… you can do the fine tuning then.

#7

sendValue() from where i have to call this?

#8

That doesn’t matter, but ONLY the first Phone has to call it. Since this Phone will be a Tag then.

The second Phone ONLY has to call receive.

#9

I have installed this app in both phone now when I am trying to share its doing nothing.

Ionic Native: deviceready event fired after 10222 ms
Initialized the NfcPlugin
WebSocket is already in CLOSING or CLOSED state.
Uncaught TypeError: Illegal invocation

#10

I simply want to share a string. basically this string I have to passed to a nfc enabled device which is not android. Initially I am testing on 2 android device so I can check that the value I want to pass that device my android app is passing same.

#11

My code I’ve provided you is working fine it must have something todo with your Page’s code. You might have something implemented wich is causing this error. OR didn’t implemented…

I can’t do much here at the momment since I have no insight of your plugins / code.


The code is doing that :slight_smile:.

#12

can you please share any working sample code? I can download that source code can try if it works for me?

#13

I did already.

HTML:


<ion-content>
    <p>User: 1</p>
    <button ion-button full (click)="sendValue()">Send Value</button>
    <br />
    <p>User: 2</p>
    <button ion-button full (click)="receiveValue()">Receive Value</button>
    <ion-input [(ngModel)]="receivedValue"></ion-input>
</ion-content>

TS:

/*Paste this string under your export class*/
  receivedValue: any;
//


sendValue() {
    //Attaching the NFC Listener
    this.nfc.addNdefListener(() => {
      this.SuccessAttach();
    }, (err) => {
      this.ErrorAttach();


    }).subscribe((event) => {
      //Send the message
      let value = this.ndef.textRecord('I am going to be sent over!');
      this.nfc.share([value]);
    });
  }*/

  receiveValue() {
    //Attaching the NFC Listener
    this.nfc.addNdefListener(() => {
      this.SuccessAttach();
    }, (err) => {
      this.ErrorAttach();


      }).subscribe((event) => {
        let alert = this.alertCtrl.create({
          subTitle: 'RECEIVED!',
          buttons: ['Dismiss']
        });
        alert.present();
      this.receivedValue = event.tag;
    });
  }


  SuccessAttach() {
    let alert = this.alertCtrl.create({
      subTitle: 'Attached Listener',
      buttons: ['Dismiss']
    });
    alert.present();
  }
  ErrorAttach() {
    let alert = this.alertCtrl.create({
      subTitle: 'Error Attaching Listener',
      buttons: ['Dismiss']
    });
    alert.present();
  }
#14

{“isWritable”:false,“id”:[0],“techTypes”:[“android.nfc.tech.Ndef”],“type”:“android.ndef.unknown”,“canMakeReadOnly”:false,“maxSize”:0,“ndefMessage”:[{“id”:[],“type”:[85],“payload”:[3,112,108,97,121,46,103,111,111,103,108,101,46,99,111,109,47,115,116,111,114,101,47,97,112,112,115,47,100,101,116,97,105,108,115,63,105,100,61,99,111,109,46,119,101,109,115,111,108,46,110,102,99,115,104,97,114,105,110,103,116,101,115,116,38,102,101,97,116,117,114,101,61,98,101,97,109],“tnf”:1},{“id”:[],“type”:[97,110,100,114,111,105,100,46,99,111,109,58,112,107,103],“payload”:[99,111,109,46,119,101,109,115,111,108,46,110,102,99,115,104,97,114,105,110,103,116,101,115,116],“tnf”:4}]}

#15

Hi @cherry, @kumailrlakhani

I am trying to send just a string from phone 1 to phone 2… but I can’t… basically the issue is: this.nfc.addNdefListener never fire .subscribe (event).

I can receive (with receiveValue() ) data from emulating a tag by other external app (NDEF Tag Emulator), but never between sendValue() and receiveValue(), I think it’s because phone 1 never fired .subscribe.

Do you have this same issue?

All help will be welcome.