joonsei
Hello, world!
joonsei
전체 방문자
오늘
어제
  • 분류 전체보기 (32)
    • nodejs (7)
    • javascript (3)
    • Elasticsearch (11)
    • Electron (1)
    • oracle (1)
    • etc (7)
    • MongoDB (1)

인기 글

최근 댓글

최근 글

joonsei
node.js를 이용하여 IOS 푸시 보내기
nodejs

node.js를 이용하여 IOS 푸시 보내기

2015. 11. 3. 12:11

PUSH란?

  • 서버에서 정보를 클라이언트로 강제 전달하는 서비스.
  • Apple의 APNS(Apple Push Notification Service)
    Google의 GCM(Google Cloud Messaging)

installation

$ npm install apns -s

API

/*
notification.payload : Push payload (json타입)
notification.badge : 뱃지 숫자 번호
notification.sound : Push 알림음
notification.alert : Push 메시지 텍스트
notification.device : Push 받을 대상
notification.encoding : 메시지 인코딩 타입 (기본 : UTF-8)
*/
const apns = require("apns"), options, connection, notification;

const options = {
    keyFile : "conf/key.pem",
    certFile : "conf/cert.pem",
    debug : true
};

const connection = new apns.Connection(options);

notification.payload = {"description" : "A good news !"};
notification.badge = 1;
notification.sound = "dong.aiff";
notification.alert = "푸시";
notification.device = new apns.Device("아이폰 토큰");

const send = connection.sendNotification(notification);

!! 여기서 한가지 주의점
Apple의 APNS Gateway는 개발용(Development), 배포용(Distribution) 이 서로 다르다.
Port는 2195로 동일

options의 gateway 값을 바꿔주면된다. (default: gateway.push.apple.com)

  • Development : gateway.sandbox.push.apple.com
  • Distribution : gateway.push.apple.com
    'nodejs' 카테고리의 다른 글
    • body-parser (urlencoded, extended 옵션)
    • req.body null 일때
    • nodejs 기본 메모리 제한
    • child_process에서 spawn, exec 차이
    joonsei
    joonsei
    IT 개발자의 소소한 기술 이야기.

    티스토리툴바