nodeJS에서 GCM notification 구현하기 :: 서버구축[SSISO Community]
 
SSISO 카페 SSISO Source SSISO 구직 SSISO 쇼핑몰 SSISO 맛집
추천검색어 : JUnit   Log4j   ajax   spring   struts   struts-config.xml   Synchronized   책정보   Ajax 마스터하기   우측부분

서버구축
[1]
등록일:2018-07-15 08:34:46 (0%)
작성자:
제목:nodeJS에서 GCM notification 구현하기


node-gcm npm은 nodejs에서 GCM notification push를 효과적으로 이루어지게 도와주는 모듈이다.


npm node-gcm 공식 사이트 : https://www.npmjs.com/package/node-gcm


node-gcm npm을 깔고 id와 apiKey를 등록하고, 안드로이드가 준비되어 있다면 아래와 같은 nodeJS코드를 활용하면 된다.

var gcm = require('node-gcm');

var message = new gcm.Message();

var message = new gcm.Message({
    collapseKey: 'demo',
    delayWhileIdle: true,
    timeToLive: 3,
    data: {
        key1: 'demo title.',
        key2: 'push demo'
    }
});

var server_access_key = 'push provider access key value';
var sender = new gcm.Sender(server_access_key);
var registrationIds = [];

var registration_id = 'android registration_id value';
registrationIds.push(registration_id);

/**
* Params: message-literal, registrationIds-array, No. of retries, callback-function
**/
sender.send(message, registrationIds, 4, function (err, result) {
    console.log(result);
});
view raw node-gcm.js hosted with ❤ by GitHub



위와 같이 매우 간단한 nodeJS코드를 통해서 push를 날릴 수 있다는 것을 알 수 있다.


나머지 안드로이드 코드는 GCM push android project로 구글링하면 나온다.

[본문링크] nodeJS에서 GCM notification 구현하기
[1]
코멘트(이글의 트랙백 주소:/cafe/tb_receive.php?no=34711
작성자
비밀번호

 

SSISOCommunity

[이전]

Copyright byCopyright ⓒ2005, SSISO Community All Rights Reserved.