【问题标题】:Firebase Plugin(FCM) is not definedFirebase 插件(FCM)未定义
【发布时间】:2018-12-29 01:07:13
【问题描述】:

尝试通过 FCM 和 Phonegap 建立推送功能,但我不断收到此错误:未定义 FCMPlugin。

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" />

控制台

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

****编辑

我在设备准备就绪时添加了一个事件侦听器,它似乎可以工作,但我的控制台给了我另一个错误。

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

这是我更新的 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) );
        }
    });
}`

【问题讨论】:

  • 一件事可能是您在 FCMPlugin 准备好之前就在使用它。
  • 我应该先做 $(document).ready(function(){ }) 吗?

标签: javascript firebase push-notification firebase-cloud-messaging phonegap


【解决方案1】:

将FCMPlugin文件路径改成你的index.html中的相同路径,所以文件必须这样调用:

<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>

与 cordova.js 文件的位置相同。最后的脚本必须是你的 index.js 脚本

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2022-07-20
    • 2016-10-24
    相关资源
    最近更新 更多