Cordova-plugin-firebasex: After upgrading to 6.0.3 getToken stopped to work

Created on 7 Aug 2019  路  17Comments  路  Source: dpa99c/cordova-plugin-firebasex

iOS 12.4

I was on 6.0.2 after upgrading to 6.0.3 getToken stopped to work.

Tried in console:
window.FirebasePlugin.getToken();
undefined

awaiting response ios

Most helpful comment

I've just published v6.0.4 which should resolve this (and related) issues.
Please regression test and report any issues in which case I'll reopen this issue.

All 17 comments

getToken() (like all plugin methods) returns its result asynchronously via a callback function, hence the synchronous return value is expected to be undefined.

Correct usage as documented is:

window.FirebasePlugin.getToken(function(token) {
    console.log(token);
}, function(error) {
    console.error(error);
});

Please build and run the example project to validate that this is indeed the case.

Sorry @dpa99c I copied wrong code to issue :) I mean that one:

window.FirebasePlugin.getToken(function(token) { console.log(token); }, function(error) { console.error(error); });

I Xcode logs i can see:

2019-08-07 12:42:24.727617+0600 Opera Build[8091:1069246] 6.3.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add[FIRApp configure];(FirebaseApp.configure()in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.
P.s. I really appreciate for your help

OK, I will look into it. I've reworked the iOS code quite a bit in v6.0.3 to add top-level try/catch blocks to prevent app crashes so it's possible I've introduced a bug.
I'll do a fresh install of the example project app on an iOS device and see if I can repro this.

On a fresh install of the example project app, I don't see the same warning:


Xcode console output

2019-08-07 12:27:24.547105+0100 FirebaseTest[724:547244]  - <AppMeasurement>[I-ACS036002] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist
2019-08-07 12:27:24.604539+0100 FirebaseTest[724:547040] Apache Cordova native platform version 5.0.1 is starting.
2019-08-07 12:27:24.604779+0100 FirebaseTest[724:547040] Multi-tasking -> Device: YES, App: YES
2019-08-07 12:27:24.835146+0100 FirebaseTest[724:547040] Using UIWebView
2019-08-07 12:27:24.839821+0100 FirebaseTest[724:547040] Starting Firebase plugin
2019-08-07 12:27:24.840073+0100 FirebaseTest[724:547040] [CDVTimer][firebaseplugin] 0.367999ms
2019-08-07 12:27:24.840121+0100 FirebaseTest[724:547040] [CDVTimer][TotalPluginStartup] 1.820087ms
2019-08-07 12:27:24.843927+0100 FirebaseTest[724:547242] _hasPermission: NO
2019-08-07 12:27:25.256966+0100 FirebaseTest[724:547040] GoogleService-Info.plist found, setup: [FIRApp configureWithOptions]
2019-08-07 12:27:25.359949+0100 FirebaseTest[724:547040] [Crashlytics] Version 3.12.0 (136)
2019-08-07 12:27:25.465417+0100 FirebaseTest[724:547243] 6.3.0 - [Firebase/Performance][I-PRF700001] Firebase Performance Diagnostics have been enabled!
2019-08-07 12:27:25.469305+0100 FirebaseTest[724:547244] 6.3.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60002000 started
2019-08-07 12:27:25.469485+0100 FirebaseTest[724:547244] 6.3.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r)
2019-08-07 12:27:25.586540+0100 FirebaseTest[724:547040] FCM direct channel = true
2019-08-07 12:27:25.643158+0100 FirebaseTest[724:547242] Metal API Validation Enabled
2019-08-07 12:27:25.701268+0100 FirebaseTest[724:547256] 6.3.0 - [Firebase/Messaging][I-FCM001000] FIRMessaging Remote Notifications proxy enabled, will swizzle remote notification receiver handlers. If you'd prefer to manually integrate Firebase Messaging, add "FirebaseAppDelegateProxyEnabled" to your Info.plist, and set it to NO. Follow the instructions at:
https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in_firebase_messaging
to ensure proper integration.
2019-08-07 12:27:25.997279+0100 FirebaseTest[724:547040] Resetting plugins due to page load.
2019-08-07 12:27:26.035681+0100 FirebaseTest[724:547040] Failed to load webpage with error: The operation couldn鈥檛 be completed. (NSURLErrorDomain error -999.)
2019-08-07 12:27:26.037086+0100 FirebaseTest[724:547040] Resetting plugins due to page load.
2019-08-07 12:27:26.165703+0100 FirebaseTest[724:547040] Finished load of: file:///var/containers/Bundle/Application/E4EFC33E-22A0-4141-83DD-26DDF6BAB551/FirebaseTest.app/www/index.html
2019-08-07 12:27:26.298727+0100 FirebaseTest[724:547040] deviceready
2019-08-07 12:27:26.302656+0100 FirebaseTest[724:547261] _hasPermission: NO
2019-08-07 12:27:26.321985+0100 FirebaseTest[724:547040] Set user ID
2019-08-07 12:27:26.322127+0100 FirebaseTest[724:547040] Set user property
2019-08-07 12:27:26.322222+0100 FirebaseTest[724:547040] Logged event
2019-08-07 12:27:26.322321+0100 FirebaseTest[724:547040] Requesting remote notifications permission
2019-08-07 12:27:26.322427+0100 FirebaseTest[724:547040] grantPermission
2019-08-07 12:27:26.324307+0100 FirebaseTest[724:547260] _hasPermission: NO
2019-08-07 12:27:27.309800+0100 FirebaseTest[724:547040] Sent screen name
2019-08-07 12:27:28.157605+0100 FirebaseTest[724:547259] 6.3.0 - [Firebase/InstanceID][I-IID023001] Couldn't add item to Keychain OSStatus: -25299
2019-08-07 12:27:28.158777+0100 FirebaseTest[724:547259] 6.3.0 - [Firebase/InstanceID][I-IID003009] Failed to fetch default token Error Domain=com.google.iid Code=-25299 "(null)"
2019-08-07 12:27:37.865576+0100 FirebaseTest[724:547245] requestAuthorizationWithOptions: granted=YES
2019-08-07 12:27:37.865701+0100 FirebaseTest[724:547245] registerForRemoteNotifications
2019-08-07 12:27:37.908806+0100 FirebaseTest[724:547259] registerForRemoteNotifications
2019-08-07 12:27:37.908880+0100 FirebaseTest[724:547259] _hasPermission: YES
2019-08-07 12:27:37.911781+0100 FirebaseTest[724:547040] Remote notifications permission granted
2019-08-07 12:27:37.918395+0100 FirebaseTest[724:547040] Got token: dR0OkgAgpBo:APA91bFjW7KVX49eIvkE2LNiB5YoRIDDZFtmK9w3Wyt4julCma00pSB-rPE5qHd7cfMgyirt1I6q51mqG65KGdwpRRi4We47s_gmACcmZqhj66AxIU5RXAPoFEB_dxxPnHj0xSXguCOq
2019-08-07 12:27:38.099835+0100 FirebaseTest[724:547040] didRegisterForRemoteNotificationsWithDeviceToken: {length = 32, bytes = 0xe3c3387d 65f53efd be611a34 31b05c31 ... ffa77110 38d8554b }
2019-08-07 12:27:38.256469+0100 FirebaseTest[724:547040] FCM direct channel = true

Please can you try to build and run the example project app on iOS to confirm whether you can reproduce the issue in a known codebase.

hi! thanks for the plugin! works great on Android
but when i got it to work now on iOS, i got the token but the push notifications is not arriving..

the permissions popup was up and i allowed it

any idea?

thanks

update:
@dpa99c thanks! it was the APNs, stopped with no notice at the same time of updating the plugin..

@medevelopment check your APNS is configured correctly for Firebase: https://firebase.google.com/docs/cloud-messaging/ios/certs

Also try to build and run the example project app as a known working reference.

I have the same problem on 6.0.3. The getToken method hangs and no returns any error on iOS:

window.FirebasePlugin.getToken(function(firebaseToken) {
console.log('firebasetoken')
}, function(error) {
});

I have already tried with the ionic firebase wrapper and not works.

The APNS certificates areis correctly configurated on firebase with both, dev and prod.

The process to update de plugin was:

-Remove Both platforms
-Remove the firebase plugins(firebasex, androidx, androidx-adapter)
-Add platforms(both latest)
-add plugins again, lates versions

My ionic info:

Ionic:

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

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.0.0, ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 17 other plugins)

Utility:

cordova-res : not installed
native-run : 0.2.8

System:

Android SDK Tools : 26.1.1 (/Users/myuser/Library/Android/sdk)
ios-deploy : 1.9.2
ios-sim : 8.0.1
NodeJS : v10.16.1 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001

My xCode related LOG:

2019-08-08 10:15:32.635728+0200 MYPROJECT[1807:368956] Starting Firebase plugin
2019-08-08 10:15:32.637842+0200 MYPROJECT[1807:368956] [CDVTimer][firebaseplugin] 2.215028ms
2019-08-08 10:15:32.637873+0200 MYPROJECT[1807:368956] [CDVTimer][TotalPluginStartup] 22.886992ms
2019-08-08 10:15:32.642370+0200 MYPROJECT[1807:369126] _hasPermission: NO
2019-08-08 10:15:32.658960+0200 MYPROJECT[1807:368956] GoogleService-Info.plist NOT FOUND, setup: [FIRApp defaultApp]
2019-08-08 10:15:32.659158+0200 MYPROJECT[1807:369147] 6.3.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.
2019-08-08 10:15:32.659474+0200 MYPROJECT[1807:369147] 6.3.0 - [Firebase/Core][I-COR000012] Could not locate configuration file: 'GoogleService-Info.plist'.
2019-08-08 10:15:32.660469+0200 MYPROJECT[1807:369140] 6.3.0 - [Firebase/Core][I-COR000005] No app has been configured yet.
2019-08-08 10:15:32.669175+0200 MYPROJECT[1807:368956] FirebasePlugin[native] ERROR: EXCEPTION: `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) could not find a valid GoogleService-Info.plist in your project. Please download one from https://console.firebase.google.com/.
2019-08-08 10:15:32.669695+0200 MYPROJECT[1807:369147] 6.3.0 - [Firebase/Core][I-COR000005] No app has been configured yet.
2019-08-08 10:15:32.815436+0200 MYPROJECT[1807:368956] FCM direct channel = true
2019-08-08 10:15:32.816772+0200 MYPROJECT[1807:369140] 6.3.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) to your application initialization. Read more: https://goo.gl/ctyzm8.

Questions:

-Why tell log that can not locate the GoogleService-Info.plist? The file is located on root folder at the moment of the installation
-Is necessary to have enabled permissions to get a token? On previous versions no
-Is mandatory to remove node_modules folder to update to new version?

Thanks for your time

@medevelopment check your APNS is configured correctly for Firebase: https://firebase.google.com/docs/cloud-messaging/ios/certs

Also try to build and run the example project app as a known working reference.

Hi @dpa99c

Did all steps. Example project also not working(Also checked that in package-lock.json cordova-plugin-firebasex version is 6.0.3). Method getToken returns "undefined".
Forked repo(cordova-plugin-firebasex) and removed commit "Remove google-services.json and GoogleService-Info.plist placeholders." then method getToken() started to work. Could please check why did you remove those files?

Hello! Like @yoldar, I have updated to 6.0.3 and on iOS, it is not registering to Firebase properly. Also, when I install cordova-plugin-firebasex in my Cordova project, the cordova-plugin-googleplus stops working. I got it to work with cordova-plugin-firebasex 6.0.0 using this but now it is not good enough. Any 6.0.4 soon? :) Thanks for the plugin btw!

I've just published v6.0.4 which should resolve this (and related) issues.
Please regression test and report any issues in which case I'll reopen this issue.

I've just published v6.0.4 which should resolve this (and related) issues.
Please regression test and report any issues in which case I'll reopen this issue.

Test application (cordova-plugin-firebasex-text) seems to be fine. Thanks a lot!

Can also confirm this fixed this issue

Hi! I am using v6.07

constructor(public platform: Platform){
   this.platform.ready().then((readySource) => {
      document.addEventListener('deviceready', this.DeviceReady, false);
   }
}

DeviceReady(){
   window.FirebasePlugin.getToken(function(token) {
      console.log(token);
   }, function(error) {
      console.error(error);
    });
}

when i run * ionic cordova run android * and compile on my phone and inspect in the browser

in console i can see next error

vendor.js:1823 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'getToken' of undefined
TypeError: Cannot read property 'getToken' of undefined
    at Channel.webpackJsonp.981.MyApp.DeviceReady (main.js:5169)
    at Channel.subscribe (cordova.js:769)
    at document.addEventListener (cordova.js:126)
    at HTMLDocument.document.addEventListener (cordova.js:1460)
    at main.js:5088
    at t.invoke (polyfills.js:3)
    at Object.onInvoke (vendor.js:5134)
    at t.invoke (polyfills.js:3)
    at r.run (polyfills.js:3)
    at polyfills.js:3
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (vendor.js:5125)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)

When i write in console window.FirebasePlugin return undefined

I have the same problem when the following code

onNotificationOpen() {
      return new Observable(observer => {
            (window as any).FirebasePlugin.onMessageReceived((response) => {
                observer.next(response);
            });
       });
}
...
this.onNotificationOpen().subscribe(data => console.log(`FCM message: ${data}`));

can anybody help me?

@dpa99c I'm getting this error with the version 6.0.7 on android app start:
TypeError: Object(...) is not a function
at FirebaseX.subscribe

It's triggered by this line:
this.firebase.subscribe("all");

Any clues?

Similar problem.

Version 6.1.0 in cordova
Cannot read property 'onTokenRefresh' of undefined.

document.addEventListener("deviceready", pushFirebaseAppReady, false);
function pushFirebaseAppReady() {
    window.FirebasePlugin.onTokenRefresh(function(token) {
        console.log("Refresh Firebase Token: " + token);
        regToken(token);
    });
}

Seems that window.FirebasePlugin remains undefined after deviceready event when using platform browser. No problem in android (tested on device).

I solved it by changing my version of cordova
Versions Supported

  • cordova: >= 9
  • cordova-android: >= 8
  • cordova-ios: >= 5

This is my ionic information

Ionic:

   Ionic CLI          : 5.2.8 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.5
   @ionic/app-scripts : 3.2.2

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.1.0, browser 5.0.3, ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-webview 2.5.1, (and 24 other plugins)

Utility:

   cordova-res : 0.6.0 
   native-run  : 0.2.8 

System:

   ios-deploy : 1.9.4
   ios-sim    : 8.0.2
   NodeJS     : v10.15.3 (/usr/local/bin/node)
   npm        : 6.4.1
   OS         : macOS Mojave
   Xcode      : Xcode 10.3 Build version 10G8

This is my current code

return new Observable(observer => {
  (window as any).FirebasePlugin.onMessageReceived((response) => {
    alert("observable");
    observer.next(response);
  });
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Akz47 picture Akz47  路  6Comments

zmoshansky picture zmoshansky  路  6Comments

auron105 picture auron105  路  7Comments

leabdalla picture leabdalla  路  7Comments

benwhomsley picture benwhomsley  路  4Comments