iOS2013. 7. 10. 15:08

PHP로 혹시 apple push notification service를 구축하려고 하시나요?

아마도 여러분께 이 포스팅이 유용할지도 모르겠네요.



최근 아이폰 어플리케이션을 런칭하면서 php로

apple push notification service를 구축하는 경험을 했습니다.


APNS(Apple Push Notification Service)는 애플 푸시 노티피케이션 서비스입니다.




아이폰에서 흔히 경험할 수 있는

어플리케이션에서 마치 문자메시지처럼 새로운 소식이나 메시지를 알려주는 서비스입니다.



대략적인 작동방식에 대한 설명을 드리자면

애플의 푸시 서버로 특정 애플 기기에 대한 token과 메시지 내용을 전달하면

애플의 푸시서버는 이를 받아 해당 token에 해당하는 기기로

푸시 메시지를 쏩니다.




APNS에 대한 애플의 문서를 번역한 자료입니다. 구축전에 한번 가볍게 읽어보시면 좋을것 같습니다.




자 그럼 이제 PHP버전의 APNS 라이브러리를 소개합니다.



1. Esay APNS




2. APNS-PHP




3. PHP-APNS





PHP의 APNS 라이브러리는 위의 3가지로 크게 나뉩니다.

그중에서도 제가 가장 강추하는 라이브러리는 1번에 소개된 EASY APNS 입니다.


추천하는 이유는 구축하기 가장 쉽고, 메뉴얼도 가장 깔끔합니다.


EASY APNS의 설치는 크게 4단계로 구분됩니다.


1. PHP 소스코드 업로드하기

2. mysql 테이블 생성하기

3. 노티피케이션 전송을 위한 cron job 설정하기

4. 아이폰 어플리케이션 소스코드에 APNS 적용하기



각각의 설치 방법은 웹사이트에 방문하시면 아주 친절하게 소개가 되어있습니다.

EASY APNS는 개발버전과 배포버전을 구분하여 push 보내기가 가능하며

사용자가 해당 어플리케이션을 삭제하였는지 feedback에 대한 처리도 하기 때문에

매우 유용합니다.


다만 이것을 구현하실 여러분들이 조금 더 수고해주셔야 하는부분은


EASY APNS의 매뉴얼대로 구축을 마치고 테스트를 하시면

EASY APNS는 사용자의 push 요청을 "큐"로 쌓아두고 있다가

cron job이 실행될때 이 쌓였던 push에 대한 요청들을 한꺼번에 처리합니다.


즉 cron job 설정을 한시간으로 해놓으면 push 가 매시각 한번씩 보내지는 것이고

1일단위로 설정해놓으셨다면 push가 일단위로 보내집니다.


그래서 혹시 즉시성을 요구하는 푸시 서비스를 구현하실때는

APNS 객체의 _pushMessage 메소드를 직접 호출하셔야 합니다.

이는 아마 소스코드 보시면 왠만한 PHP개발자 분들이라면 알수 있기에 자세한 설명은 넘어가겠습니다.



개발자분들의 칼퇴를 기원하며....


출처 : http://trend21c.tistory.com/1049

'iOS' 카테고리의 다른 글

PHP - cURL 비동기 통신  (0) 2013.12.01
셀 높이 조절  (0) 2013.06.25
앱 정보 가져오기 (앱이름, 버전)  (0) 2013.06.19
스토리보드 커스텀 셀 (공개)  (0) 2013.06.12
유니코드 출력  (0) 2013.02.01
Posted by 다오나무
node.js2012. 10. 31. 10:41

It’s coming up to a year since we launch our server monitoring iPhone application and so our Apple push notification SSL certificate is expiring in a few weeks. It is necessary to renew it and install the new certificate on our servers so we can continue sending push notifications for server alerts, and this quick post will take you through the steps.

You can generate a new certificate without revoking the old one, and use them simultaneously to ensure they are working before revoking the old one.

1) Log in

iPhone Portal App IDs

Log into the Apple iPhone Developer website and click the iPhone Provisioning Portal link. From the left menu, click on App IDs and then Configure next to the app you want to regenerate the certificate for. You’ll see your existing certificates and the option to generate a new one. Click the Configure button to launch the wizard.

2) Generate a CSR

I used the CSR I generated for the original APNS certificate but you can generate a new one by following the instructions in the wizard.

3) Generate the certificate

iPhone Portal Generate

After uploading the CSR, the wizard will generate your new certificate. The name will show up as your username rather than what you specify in the CSR. Download it to your system, it will be called aps_production_identity.cer. Double click it to import it into your Keychain.

4. Export certificates / keys

Launch Keychain Assistant from your local Mac and from the login keychain, filter by the Certificates category. You will see an expandable option called “Apple Development Push Services”. You’ll see your old certificate and the new one you just downloaded.

Click the triangle to expand the certificate. You’ll have 2 items – the certificate itself that you just expanded, and the private key that was revealed.

Keychain Export

Right click on the certificate (not the private key) “Apple Development Push Services” > Export “Apple Development Push Services ID123″. Save this as apns-prod-cert.p12 file somewhere you can access it. Then do the same with the private key and save it as apns-prod-key.p12.

For both exports, you will be asked to specify a password, then asked for your keychain password. I did not specify a password on the first prompt.

5) Convert to PEM format

These files now need to be converted to the PEM format by executing these 2 commands from the terminal:

1
2
openssl pkcs12 -clcerts -nokeys -out apns-prod-cert.pem -in apns-prod-cert.p12
openssl pkcs12 -nocerts -out apns-prod-key.pem -in apns-prod-key.p12

You will be forced to set a PEM passphrase on the second command, so execute the following command to remove it:

1
openssl rsa -in apns-prod-key.pem -out apns-prod-key-noenc.pem

6) Merge files

Finally, you need to combine the key and cert files into a apns-prod.pem file we will use when connecting to APNS:

1
cat apns-prod-cert.pem apns-prod-key-noenc.pem > apns-prod.pem

And that’s it. You can replace your existing production certificate with the one you just created, and it’ll be valid for another year. Yay.


정리를 해보자.

응용프로그램 -> 키체인 접근  프로그램을 연다.

그리고 해당 푸쉬 인증서 삼각형 세모를 누르면 개인키가 보인다.

일단 인증서만 클릭해놓고 apns-prod-cert.p12 파일로 내보낸다.

그리고 개인키만 클릭해놓고 apns-prod-key.p12 파일로 내보낸다.


그리고 터미널을 실행해서 다음과 같은 명령을 실행한다.

openssl pkcs12 -clcerts -nokeys -out apns-prod-cert.pem -in apns-prod-cert.p12
openssl pkcs12 -nocerts -out apns-prod-key.pem -in apns-prod-key.p12

apns-prod-key.pem 을 만들때 암호를 지정할수밖에 없는데
이제 그 암호를 제거해서 보자. 다음 명령을 입력한다.

openssl rsa -in apns-prod-key.pem -out apns-prod-key-noenc.pem

이제
인증서 파일과 키 파일을 결합하면 된다.

cat apns-prod-cert.pem apns-prod-key-noenc.pem > apns-prod.pem

를 입력하자.


ps. 하지만 실상 node.js apns 에서 필요한 파일은
apns-prod-cert.pem 파일과 apns-prod-key-noenc.pem 파일만 있으면 된다.

수고했다.


'node.js' 카테고리의 다른 글

node.js 에서 debugger 를 사용해보자.  (0) 2012.10.26
node.js 설치 방법 및 샘플  (0) 2012.07.09
Posted by 다오나무