简体   繁体   中英

Firebase Plugin(FCM) is not defined

Trying to establish push capabilities via FCM and Phonegap, but i keep getting this error: FCMPlugin is not defined.

index.js

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) );
 }
});

index.html

<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="plugins/cordova-plugin- 
fcm/www/FCMPlugin.js"></script>

config.xml

<plugin name="cordova-plugin-whitelist" spec="~1.3.3" />
<plugin name="cordova-plugin-device" spec="~1.1.7" />
<plugin name="cordova-plugin-fcm" spec="~2.1.2" />

Console

index.js:55 Uncaught ReferenceError: FCMPlugin is not defined
at index.js:55
(anonymous) @ index.js:55
(index):84 adding proxy for Device
(index):84 adding proxy for Battery
(index):84 adding proxy for Camera
(index):84 adding proxy for File
(index):84 adding proxy for Capture
(index):84 adding proxy for Globalization
(index):84 adding proxy for InAppBrowser
(index):84 adding proxy for NetworkStatus
(index):84 Error: exec proxy not found for :: FCMPlugin :: ready
(index):84 FCMPlugin Ready ERROR
(index):84 FCMPlugin.js: is created
(index):84 Persistent fs quota granted

****Edit

I added an event listener for when device is ready, and it seemed to work, yet my console gives me another error.

Error: exec proxy not found for :: FCMPlugin :: ready
(index):84 FCMPlugin Ready ERROR
(index):84 FCMPlugin.js: is created
(index):84 Persistent fs quota granted
(index):84 Error: exec proxy not found for :: FCMPlugin :: 
registerNotification

Heres my updated JS

   document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    var deviceID = device.uuid;
    localStorage.uuid = deviceID;
    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) );
        }
    });
}`

Change the FCMPlugin file path to the same path in your index.html, so the file must be called in this way:

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="FCMPlugin.js"></script>
<script type="text/javascript" src="js/index.js"></script>

The same location as the cordova.js file. And the final script must be your script for index.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM