Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

FCM server response error (pushID?) NotRegistered #1812

Closed
rolinger opened this issue Jun 26, 2017 · 17 comments
Closed

FCM server response error (pushID?) NotRegistered #1812

rolinger opened this issue Jun 26, 2017 · 17 comments

Comments

@rolinger
Copy link

Expected Behaviour

Push notification sent from server should be getting "success=1", instead getting "failure=1" and "error=NotRegistered"

Actual Behaviour

Server side error received when trying to push to the phone:
object(stdClass)#4 (5) { ["multicast_id"]=> int(4650881156566144680) ["success"]=> int(0) ["failure"]=> int(1) ["canonical_ids"]=> int(0) ["results"]=> array(1) { [0]=> object(stdClass)#5 (1) { ["error"]=> string(13) "NotRegistered" } } }

Reproduce Scenario (including but not limited to)

I am successfully getting a pushID using my registered senderID. I save that pushID to my server db and then use another script on the server to send a notification to that pushID. That's when i get the "error=NotRegistered" - I think this means the pushID is not registered and therefor is invalid...but how is it possible to even get an invalid pushID?

I actually had all this working two weeks ago and suddenly it all stopped working. I have no idea whats going on. I validated my senderID (app side) and server key (server side) are correct:

Steps to Reproduce

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android: 7.0

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Android LG K20- Plus

Cordova CLI version and cordova platform version

cordova --version : 6.5.0
cordova platform version android: 6.1.2

Plugin version

cordova plugin version | grep phonegap-plugin-push: 1.10.4

Sample Push Data Payload

Sample Code that illustrates the problem

  var push = PushNotification.init({
    "android": {
      "senderID" : "21568......",
      "forceShow" : "true",
      "vibrate" : "true",
      "sound" : "true"
    },
    browser: {
            },
    ios: {
      alert: "true",
      badge: "true",
      sound: "true"
    },
    windows: {}
  });

  var enabledAPI,regAPI = 0 ;
  pushEnabled($q).then(function(status) {
    enabledAPI = status ;  // push enabled or not
    return pushReg($q) ;
  }).then(function(status) {
    regAPI = status ;  // pushID changed or not
    if (enabledAPI == 1 || regAPI == 1) {
      apiService.all(... ... ) ;
    }
  }) ;

  function pushEnabled($q) {
    var q = $q.defer() 
    PushNotification.hasPermission(function(data) {
      var oldPushEnabled = getDB('dev_pushEnabled') ;
      if (data.isEnabled == true) { 
          var pushEnabled = 1 ; 
        } else {
          var pushEnabled = 0 ;
      }
      if (oldPushEnabled != pushEnabled) {
        setDB('dev_pushEnabled',pushEnabled,1) ;
        q.resolve(1) ;  // push enable status has changed
      } else {
        q.resolve(0) ;  // push enable status has not changed
      }
    });
    return q.promise ;
  }

  function pushReg($q) {
    var q = $q.defer() ;
    push.on('registration', function(data) {
      var oldRegId = getDB('dev_pushID');
      if (oldRegId != data.registrationId) {
       // Save new registration ID
        setDB('dev_pushID', data.registrationId,1);
        // Post registrationId to your app server as the value has changed
        q.resolve(1) ;  // pushID has changed
        console.log("IDs have CHANGED!") ;
      } else {
        console.log("IDs the same") ;
        q.resolve(0) ;  // pushID has not changed.
      }
    });
   return q.promise
  }

Logs taken while reproducing problem

@macdonst
Copy link
Member

@rolinger push plugin 1.10.3 uses GCM but you are trying to send via FCM. That's probably why you are getting an invalid registration ID error from the server. Did you recently move the server side to FCM?

@rolinger
Copy link
Author

@macdonst - I only installed all these plugins just two weeks ago. And got everything working...and from the beginning I used FCM...a few days ago I noticed it was breaking and can't explain why it was working and now its not. What plugin version should I be using for FCM?

@macdonst
Copy link
Member

@rolinger FCM support is in the 2.0.0 stream which is currently on RC5 and I hope to be officially out soon. You might want to try forcing a new registration of your app by uninstalling and installing again.

@rolinger
Copy link
Author

@macdonst - I see in version 2.0 you removed senderID and replaced with the google-services.json file. I def have not installed the google-services.json file and mine is using the senderID....so mine was working with the current version (1.10.4) as I was receiving push msgs to my phone. In fact I have log messages from June 1st when I originally got all working...it was over the last week I noticed that it wasn't working while testing new app features that required a push notification to be sent.

Did something change? I see a new version 1.10.5 was pushed two weeks ago.

@rolinger
Copy link
Author

rolinger commented Jun 26, 2017

@macdonst - i have uninstalled and reinstalled my app several times now...after each new install I am def getting a new pushID. Oh...and I am on 1.10.4...in your first response you said 1.10.3

@macdonst
Copy link
Member

@rolinger okay cool, with that data point we can reasonably be sure it is the GCM/FCM difference. The biggest difference between 1.10.4 and 1.10.5 is upgrading from GCM 10.2 to 11.

@rolinger
Copy link
Author

hmmmm, ok...so something did change. What should my next action be?

@macdonst
Copy link
Member

@rolinger if you are using 1.10.x try sending via GCM. If you are stuck with FCM then upgrade to the 2.x stream.

@rolinger
Copy link
Author

@macdonst - since everything I have worked with thus far has been FCM, will my senderIDs/Server Keys be different using GCM? Meaning that I need to separately register my app with GCM? Or does it just require sending push notices to the GCM server vs the FCM server? Currently I am sending to https://fcm.googleapis.com/fcm/send - what would that change to?

I will try this route first...if it does not work then I will upgrade the plugin to 2.0 for FCM.

@rolinger
Copy link
Author

I decided to move to phonegap-plugin-push@2.0.0-rc5. Thus in order to do that I had to update my cordova platform update android@6.2.1 - which then also forced me to update cordova-plugin-admobpro@latest. Ok...got everything update and installed...then added back in phonegap-plugin-push@2.0.0-rc5...it adds just fine. But when I compile the app...well, it downloads damn near 100 *.pom files...and around the 100th 'download' it fails with this error:

  • What went wrong:
    A problem occurred evaluating root project 'android'.

Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
For input string: "+"

Now, based on other reading, I don't have plugin-firebase or plugin-analytics so I don't know what is causing this issue. How can I fix it?

Here are my plugins:
br.com.dtmtec.plugins.carrier 1.0.0 "Carrier"
cl.rmd.cordova.dialoggps 0.0.2 "DialogGPS"
com.lampa.startapp 0.1.4 "startApp"
com.ludei.webview.plus 2.4.3 "Webview+"
com.phonegap.plugins.nativesettingsopener 1.0 "Native settings"
com.verso.cordova.clipboard 0.1.0 "Clipboard"
com.vliesaputra.deviceinformation 1.0.1 "DeviceInformation"
cordova-custom-config 3.1.2 "cordova-custom-config"
cordova-instagram-plugin 0.5.4 "Instagram"
cordova-plugin-admobpro 2.29.0 "AdMob Plugin Pro"
cordova-plugin-appavailability 0.4.2 "AppAvailability"
cordova-plugin-appinfo 2.1.1 "AppInfo Plugin"
cordova-plugin-apprate 1.2 "AppRate"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-device-motion 1.2.3 "Device Motion"
cordova-plugin-device-orientation 1.0.5 "Device Orientation"
cordova-plugin-dialogs 1.3.1 "Notification"
cordova-plugin-email 1.2.6 "EmailComposer"
cordova-plugin-extension 1.5.1 "Cordova Plugin Extension"
cordova-plugin-fastrde-checkgps 1.0.0 "checkGPS"
cordova-plugin-file 4.3.1 "File"
cordova-plugin-geolocation 2.4.1 "Geolocation"
cordova-plugin-globalization 1.0.5 "Globalization"
cordova-plugin-inappbrowser 1.6.1 "InAppBrowser"
cordova-plugin-request-location-accuracy 2.2.0 "Request Location Accuracy"
cordova-plugin-sim 1.3.3 "SIM"
cordova-plugin-splashscreen 4.0.1 "Splashscreen"
cordova-plugin-statusbar 2.2.1 "StatusBar"
cordova-plugin-vibration 2.1.3 "Vibration"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sms-plugin 0.1.11 "Cordova SMS Plugin"
cordova.plugins.diagnostic 3.4.2 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
phonegap-facebook-plugin 0.12.0 "Facebook Connect"
phonegap-plugin-push 2.0.0-rc5 "PushPlugin"

@macdonst
Copy link
Member

@rolinger yeah that is issue #1718 because Google doesn't like the + in dependencies when you apply the Google Play Services gradle plugin. I don't have a work around for that yet.

@rolinger
Copy link
Author

rolinger commented Jun 27, 2017

@macdonst - ok...so my specific issue is related then. Interestingly though, the line that it says is throwing the error doesn't have the + at the end of it. So where is it referencing the + to throw the error? This is the line throwing the error for me, it comes specifically from the /platforms/android/phonegap-plugin-push/MyProtjectName-push.gradle. Could I apply one of the solutions from #1718 by adding the @9.8.0 to the end of the reference:

ext.postBuildExtras = {
    apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}

ie: apply plugin: com.google.gms.googleservices.GoogleServicesPlugin@9.8.0 ???

@rolinger
Copy link
Author

rolinger commented Jun 27, 2017

@macdonst - I also want to make certain I am doing this correctly and there is nothing on my end I am doing wrong. In the Installation documentation for 2.0 you reference the the following SDKs:

Compilation

As of version 2.0.0 the plugin has been switched to using pinned version of Gradle libraries. You will need to ensure that you have installed the following items through the Android SDK Manager:

Android Support Library version 25.1.0
FirebaseMessaging Library version 9.8.0

And then provide a screen shot that both A) only shows Android Support Library 23.0.1 and B) does not even list the FirebaseMessaging library. When I open my SDK Manager I have Android Support Library 23.2.1 and can't find anyway to upgrade it to 25.0.1 or higher...also can't find a specific way to even add the Firebase Library. Can you comment on this?

Do I still need to apply those SDKs...and if so, how do I do it. I am on Windows 7, and I did the android update sdk -no-ui --filter command and it looks like it pulled down a bunch of legacy sdk's that I had not loaded via the SDK Manager - now those SDKs are showing downloaded. So I am not certain how to get those two specific SDKs. Thanks.

@rolinger
Copy link
Author

@macdonst - found this, could this be of use (last comment by: qpa99c ) ???

cordova-android-play-services-gradle-release

@rolinger
Copy link
Author

rolinger commented Jun 27, 2017

@macdonst - downgraded back down to v1.10.5...recompiled and reinstalled my app. I honestly have NO IDEA why this is happening - but now its working!

  1. 3 weeks ago installed phonegap-plugin-push@1.10.4 - got everything working.
  2. This past week wasn't receiving messages...something broke.
  3. Upgraded phonegap-plugin-push@1.10.5 - still wasn't working
  4. Removed phonegap-plugin-push, started doing prerequisites for @2.0.0-rc5
  5. Upgraded Cordova-Android to 6.2.1
  6. Forced me to upgrade cordova-plugin-admobpro to latest version
  7. Compiled app and all was working fine
  8. Installed latest version of phonegap-plugin-push@2.0.0-rc5, installed fine
  9. Compiled app, broke on the above issues related to GoogleServicesPlugin + issue
  10. Removed 2.0.0-rc5
  11. Added phonegap-plugin-push@1.10.5 (back to the original rev)
  12. Compiled just fine
  13. Completely reinstalled my app, a new device pushID was created.
  14. Used pushID directly in Firebase Console Notifications section and pushed several messages to my device - all worked.
    15. App registration sends email with confirmation link, clicked on link, server sent push notification successfully!!! Hadn't gotten this far since it originally worked 3 weeks ago.
  15. Reclicked the email link again, and again the push notice was received again!!!
  16. Back in Firebase Console...tested pushID one more time and again it too worked.

In my app, I am using senderID to generate the pushID:

  var push = PushNotification.init({
    "android": {
      "senderID" : "2156......",
      "forceShow" : "true",
      "vibrate" : "true",
      "sound" : "true"
    },
    browser: {
    },
    ios: {
      alert: "true",
      badge: "true",
      sound: "true"
    },
    windows: {}
  });

And in my server, I am using that pushID in the following PHP script:

  $headers = array(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
  );
  // fcm server: https://fcm.googleapis.com/fcm/send
  // gcm server: https://android.googleapis.com/gcm/send
  $ch = curl_init();
  curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
  curl_setopt( $ch,CURLOPT_POST, true );
  curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
  curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
  curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
  curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fcmFields ) );
  $result = curl_exec($ch );
  curl_close( $ch );
  return json_decode($result) ;

So...in short....phonegap-plugin-push v1.10.5, using senderID to generate pushID and sending FCM messages to https://fcm.googleapis.com/fcm/send

I changed nothing in my app code or server code. All I really did was upgrade from 1.10.4 to 1.10.5...didn't work. Upgraded to 2.0.0 didn't work...then downgraded back to 1.10.5 and now its all working again.

@rolinger
Copy link
Author

After it was all working again...I tested like 10 times. I moved on to other coding...testing some non-related app registration stuff. Uninstalled my app...then reinstalled...and now push notifications are not working again. However, this time all the messages appear to be sending from my server and the FBC Notification console...but the messages are not arriving.

@lock
Copy link

lock bot commented Jun 3, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants