Apple Push Notification Service 서버를 구현하려면


푸시 관련 인증서가 필요한데


SSL 인증서와 키 파일이 필요합니다.


하지만 그 전에 준비가 필요합니다.






1. Make sure to turn it on the "Push Notifications" service of your app id.


앱 아이디 설정에서 Push Notifications 서비스가 활성화되어 있는지 확인해야합니다.







2. Create a certificate for "Apple Push Notification service SSL"


새로운 인증서를 만드는데 Apple Push Notification service SSL 로 생성해줍니다.


생성한 후에 aps_development.cer 파일을 다운받아 Key Assistance에 추가해줍니다.






3. Export certificate with only "Apple Development IOS Push Services" (without select key)


인증서를 펼쳐보면 개인키가 포함되어 있는것이 보이는데


개인키를 선택하지 않은 상태로 export 하여 apns_cert_dev.p12 로 뽑아줍니다.







4. Export key with private key certification (select both certificate and private key)


이번에는 인증서와 개인키를 모두 잡고 export 하여 apns_key_dev.p12 로 뽑아줍니다.




5. Convert p12 file to pem file with openssl


openssl을 이용하여 각 p12 파일을 pem 파일로 변환해줍니다.


openssl pkcs12 -in apns_cert_dev.p12 -out apns_cert_dev.pem -nodes
openssl pkcs12 -in apns_key_dev.p12 -out apns_key_dev.pem -nodes






6. Use pem files with node.js "apn" plugin.


var APN = require( "apn" );

var apnsOption = {};

apnsOption.errorCallback = errorListener;

apnsOption.gateway = "gateway.push.apple.com";

apnsOption.cert = "apns_cert_dev.pem";

apnsOption.key = "apns_key_dev.pem";

apnsOption.passphrase = "????";


var apns = new APN.Connection( apnsOption );


var list = [ new APN.Device( "device token to recieved" ) ];


var message = new APN.Notification();

message.expircy = Math.floor( Date.now() / 1000 ) + 1 * 60 * 60;

message.badge = 1;

message.sound = "ping.aiff";

message.alert = "Hi there~";

message.payload = {}; // parameter to send.


apns.pushNotification( message, list );


위와 같이 apn 플러그인을 사용하여 푸시 메세지를 보낼 수 있다.




+ Recent posts