fechanique / cordova-plugin-fcm

Google FCM Push Notifications Cordova Plugin
623 stars 998 forks source link

TypeError: Object #<FCMPlugin> has no method 'onTokenRefresh' #210

Open zahid492 opened 7 years ago

zahid492 commented 7 years ago

0 185890 log FCMPlugin.js: is created 1 185942 log FCMPlugin Ready OK 2 189556 error TypeError: Object # has no method 'onTokenRefresh' at http://10.0.0.6:8100/js/controllers.js:26:11 at http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:56238:19 at Object.ionic.Platform.ready (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:2140:9) at Object.self.ready (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:56231:26) at new (http://10.0.0.6:8100/js/controllers.js:25:19) at Object.instantiate (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:18015:14) at $controller (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:23417:28) at self.appendViewElement (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:59908:24) at Object.switcher.render (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:57901:41) at Object.switcher.init (http://10.0.0.6:8100/lib/ionic/js/ionic.bundle.js:57821:20)

tessdar commented 7 years ago

Are you using Ionic? I'm not sure it works but for me, it does. 1) add onload event into body tag in index.html

2) add below cods in app.js before angular.module // Firebase Cloud Message Load function onLoad() { document.addEventListener("deviceready", function () { FCMPlugin.onTokenRefresh(function (token) { // some behaviour to send token to safe backend server alert(token); }); //FCMPlugin.onNotification( onNotificationCallback(data), successCallback(msg), errorCallback(err) ) //Here you define your application behaviour based on the notification data. FCMPlugin.onNotification(function (data) { if (data.wasTapped) { //Notification was received on device tray and tapped by the user. alert(JSON.stringify(data)); } else { //Notification was received in foreground. Maybe the user needs to be notified. alert(JSON.stringify(data)); } }); }, false); } 3) As long as I know, ngcordova doesn't have wrapper API yet. so, in order to avoid error messages, I think you need to use javascript instead of angularjs.