0
我想使用Google雲消息傳遞從流星網站向Android應用程序發送推送通知。如何在流星網絡應用程序中實現GCM
我想使用Google雲消息傳遞從流星網站向Android應用程序發送推送通知。如何在流星網絡應用程序中實現GCM
我這樣做的方式是使用包raix:push
。
爲此,首先安裝軟件包,然後在根目錄中設置一個config.push.json
文件。該文件包含推送通知的設置。你可以有一個最基本的文件,您可以使用谷歌雲消息就是:
Meteor.methods({
"sendPush": function(title, text, userId){
Push.send({
from: 'yourName',
title: title,
text: text,
query:{userId: userId}
});
}
});
,並呼籲:
{
"gcm":{
"apiKey":"yourApiKey",
"projectNumber": 000000000
}
}
然後你就可以通過調用流星方法來發送推送通知
Push.allow({
// Change this to determine whether the user with id userId can send
// the notification
send: function(userId, notification) {
return true; // Allow all users to send
}
});
在服務器上。
上述方法會向_id等於userId的用戶發送推送通知。您可以使查詢更加複雜,以便一次發送多個通知,但請記住,具有用戶標識的字段被稱爲userId
,因爲此程序包會創建一個新的集合以發送通知。
該軟件包記錄得相當好:https://github.com/raix/push。只需按照android的說明,並看看這個簡單的例子。
如果您沒有api密鑰或項目編號,則可以按照文檔中的說明設置Google雲消息傳遞。