0
在基於節點的應用程序中使用GCM需遵循的步驟是什麼? 服務器端(Node js)和客戶端(Android/iOS)都需要特定的代碼嗎?Google節點中的雲消息js
在基於節點的應用程序中使用GCM需遵循的步驟是什麼? 服務器端(Node js)和客戶端(Android/iOS)都需要特定的代碼嗎?Google節點中的雲消息js
node-gcm
包的推送。基本例如:
const gsm = require('node-gsm');
const gcmKey = ''; // Your gcm key in quotes
const deviceToken = ''; // Receiver device token
const sender = new gcm.Sender(gcmKey);
var message = new gcm.Message();
message.addData({
title: 'Push',
body: 'This is push notification',
otherProperty: true,
});
sender.send(message, {registrationIds: [token]}, (err) => {
if (err) {
console.error(err);
}
else {
console.log('Sent');
}
});
謝謝哥們。 如何在本地主機上測試此功能? 我正在構建服務器,需要測試之前的事情。 –
你可以在沒有任何服務器的情況下使用示例代碼。您只需設置適當的gcmKey和deviceToken並運行腳本。據我所知,模擬器無法收到推送消息。因此,您需要將應用程序的開發版本安裝到設備中,並手動從它複製deviceToken,或通過網絡將其發送到本地IP地址。 –