0
自從上週我試圖使用Phonegap和AngularJS從FCM獲取通知。在控制器中調用FCM工廠以獲取通知數據
我可以cordova-fcm-plugin做到這一點,所以現在我想從信息獲取數據,他們建議使用此代碼:
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));
}
},
function(msg){
console.log('onNotification callback successfully registered: ' + msg);
},
function(err){
console.log('Error registering onNotification callback: ' + err);
}
);
我的問題是,我不知道如何添加代碼對角控制器,所以我搜索了類似的互聯網的東西,我發現這個factory
angular.module('rhoAppApp')
.factory('$FCMPlugin', $FCMPlugin);
$FCMPlugin.$inject = [];
function $FCMPlugin() {
var service = {
getToken: function(successCallback, failCallback) {
FCMPlugin.getToken(successCallback, failCallback);
},
onNotification: function(onNotification, onCallbackSuccesSet, onCallbackFailSet) {
FCMPlugin.onNotification(onNotification,
onCallbackSuccesSet, onCallbackFailSet);
}
};
return service;
}
所以現在我的問題是使用該工廠在我的控制,我知道(也許我錯了),你必須調用它來自:
.controller('MainCtrl', function ($FCMPlugin) {
$FCMPlugin.something
})
但我不知道如何使用該工廠,我從來沒有使用過一個之前。