0

我正在使用Phonegap创建移动应用程序。我想使用FCM创建推送通知。我使用了cordova-plugin-firebase插件。但它显示错误。确实卡在项目中在Phonegap中推送通知?

+0

你有什么迄今所做?请在这里发布你的代码。 –

+0

我安装了下面的插件

+0

在这里发布你的错误,你得到了什么错误? –

回答

0

1)安装插件(你已经这样做)

cordova plugin add [email protected] --save 

2)从你的火力帐户下载两个文件并保持文件的根文件夹:

google-services.json 
GoogleService-Info.plist 

3)在onDeviceReady写这样的代码()方法:

onDeviceReady: function() { 
    window.FirebasePlugin.onTokenRefresh(function(token) { 
    //save this server-side and use it to push notifications to this device 
    console.log(token); 
    }, function(error) { 
    console.error(error); 
}); 
} 

这里完整index.js代码:

var app = { 
// Application Constructor 
initialize: function() { 
    this.bindEvents(); 
}, 
// Bind Event Listeners 
// 
// Bind any events that are required on startup. Common events are: 
// 'load', 'deviceready', 'offline', and 'online'. 
bindEvents: function() { 
    document.addEventListener('deviceready', this.onDeviceReady, false); 
}, 
// deviceready Event Handler 
// 
// The scope of 'this' is the event. In order to call the 'receivedEvent' 
// function, we must explicitly call 'app.receivedEvent(...);' 
onDeviceReady: function() { 
    window.FirebasePlugin.onTokenRefresh(function(token) { 
     //save this server-side and use it to push notifications to this device 
     console.log(token); 
     }, function(error) { 
     console.error(error); 
    }); 
}, 
}; 
+0

已添加这些外部文件 –

+0

是否需要在index.html文件中添加外部文件链接? –

+0

我没有添加GoogleService-Info.plist文件,我只想用于Android.So GoogleService-Info.plist文件是强制性的? –