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文件是強制性的? –