Apple Push Notification Service (APNS): How your server push notifications to your apps?

Say, you have your own server, you want to push notifications to your apps, how to do that? Well, basically it should be easy because Apple do that for you by Apple Push Notification Service (APNS). But it’s not quite easy enough because the authentication process is cumbersome.

It’s all about authentication

Your Server -> APNS -> Your iOS apps

Under your provisioning profile, you have an App ID, if you want to enable the Push Notification, you need to create a certificate for it.

This is the way you do:

  • Create public/private key.
  • Create certificate signing request (CSR)
  • Upload the CSR to Apple to create certificate
  • Download the certificate
  • Convert the certificate to cert.pem
  • Convert private key to key.pem
  • Feed key.pem and cert.pem to your server
  • Get device token and upload it to your server
  • Start push notification in your server

CSR vs Certificate:

CSR is a request that you tell Apple you wan to get a certificate. You signed on it (with private key) first, submit to Apple and after Apple agrees your request, he generates a certificate and signed on it and give it to you.

Basically, a certificate is just like a paper that signed with you and Apple. It is a registration of your private key and your private key somehow represent yourself. It’s all about an identity of YOU.

Convert the certificate to cert.pem

In keychain access, find the certificate named “Apple Development iOS Push Server: appID”, export (cmd+shift+E) to dev_cert.p12.

Convert private key to key.pem

In keychain access, export the private key associated with the certificate to dev_key.p12.

And make it unencrypted:

The Client Side

The client side is relatively easy: just tell iOS you want to register remote notification and implement some delegate functions.

This method will show up an alertView asking the user to agree with your push notification request, if the user disagree, you’ll get no tokens.

A very nice ref: iOS用戶端的APNS服務簡介與實現

And some nice refs that are helpful to understand the concept:

Fastest: Nginx + WordPress

Fastest Approach

Recently, I found this nice repo, which is a linux script helping you build a website based on nginx/php/mysql/wordpress (or non-wordpress).

It’s awesome, quick and easy.

To see how awesome it is:

And visit

Live 1080p video streaming from the Raspberry Pi to browsers using nginx and rtmp

Gstremer + RTMP + Browser

This approach is mainly referenced from here except that I use gstraemer as streaming/encode provider instead of ffmpeg. Gstreamer is an awesome media framework for streaming service. It is not only powerful but also flexible. The plugin-based architecture makes it very flexible in any situations, from codecs to communication protocols.

Install Gstreamer

Gstreamer are composed by a gstreamer core and some plugins libraries. Installation please reference this post. Notice that we’re going to use gstreamer’s rtmp module, which is contained in gst-plugins-bad, you must make sure that you have librtmp-dev installed before you compile gst-plugins-bad.

Install Nginx & Nginx-rtmp module

While gstreamer are good at video encoding and streaming, it’s not probably the best server solution facing the public. We need nginx to re-transmit the rtmp packets to allow multiple client connections.

Make sure /etc/nginx is empty because make install will not overwrite files which already exists.

Make a temporary folder to build codes

Check nginx version and start server.

Setting nginx

Edit nginx.conf

Restart server

Install flash rtmp player: StorbeMediaPlayback

For client side playback, I use strobe media playback which is an open source media framework from adobe. It seems that it’s not maintained since 2012, but it works great!

Some helpful video tutorial here

setup index.html

Edit /var/www/html/index.html and modify {pi_address} to valid address

Start Streaming

Pipe video stream from gstreamer to nginx by rtmp

Open browser and visit

Status Monitor

Demo (OSX):

Open Chrome, Safari, Firefox at the same time.
Screen Shot 2014-09-16 at 下午5.06.02

Backup everythin

Here’s a very nice post for backing up SD card as an image.


OSX的套件管理工具brew可以說是相當方便的工具,brew有時候(or always?)會下載source code來build,放在他自己的資料夾/usr/local/Cellar/,然後再link到系統目錄(通常包括但不限於/usr/local/opt/)。

但是就在link這個階段,常常需要sudo權限去寫系統目錄,而brew本身為了安全考量,不能直接使用sudo brew,除非brew執行檔的擁有者是root。這樣安全歸安全,但每次link都要改目錄(而且很可能不只一個)的寫入權限,link完再改回來,實在是很不方便。

如果你跟我一樣也喜歡簡單一點的人生,就把brew擁有者改成root吧! (At your own RISK!!)

Compile & Install Gstreamer on Raspberry Pi


Download these
* gstreamer/gstreamer
* gstreamer/gst-plugins-base
* gstreamer/gst-plugins-good
* gstreamer/gst-plugins-bad
* gstreamer/gst-plugins-ugly

from GStreamer source, at the time writing this post, the latest version I use is 1.4.1

For gst-plugins-base, gst-plugins-good and gst-plugins-ugly, simply

For gst-plugins-bad, there’s a little problem during normal installation. In old times, gst-plugins-gl was required for gst-plugins-bad and now it is merged into gst-plugins-bad, at least they claim so, but somehow there’s some bug in there at this moment, which cause gst-plugins-bad could not find gst-plugins-gl and gst-plugins-gl cannot be installed due to the fact that the author thinks there’s no need to install it since it has been merged into gst-plugins-bad.

So we need some hack for this. Fortunately, this thread has already worked it out. Follow those steps and you should get rid off the trouble.

Edit environment variable

in ~/.bashrc add a line

and reload bash file:

Test command:

If you’ve installed rpicamsrc:


如何一次控制多台ec2 server

Introduce fabric

這是一個類似ruby capistrano的軟件,專門用來處理deploy的事,也可以用來命令多個伺服器做事情。




這一段設定fab的連線環境,hosts可以是包含多個server address的array,方便吧!除此之外,fabfile.py的內容其實就是一般的python,比較特別的是,用fab指令執行的function會依序在每台機器上執行。例如在本機電腦輸入

然後你會看到fab依序連線到每個host,並執行hello(),然後將輸出顯示在local terminal。這很適合為每台機器做一些初始設定,像是init()裡面做的事。

然而,目前還不曉得如何在不同server給不同的function argument進去。待續…





  1. 安裝sublime的rsub套件,cmd+shift+p,選擇install package叫出套件管理程式,然後搜尋rsub,安裝
  2. 編輯你的ssh config,新增一個


  1. 安裝rsub




接著就會看到local端跳出sublime,編輯你的remote file,只要local端一儲存,remote也跟著儲存,酷吧!!









1. 啟動GoAgent
2. 在瀏覽器設定proxy server


下載GoAgent(支援Windows/OSX/Linux):放心,這沒病毒,無需安裝,Windows使用者請開啓local資料夾底下的goagent.exe (記得用系統管理員身分執行),然後會出現一個黑色小視窗,把他縮到右下角工具列。OSX/Linux的使用者請用 python執行,記得加sudo。




螢幕快照 2013-12-14 上午1.08.54.png

螢幕快照 2013-12-14 上午1.09.06.png


到chrome webstore下載並安裝外掛SwitchySharp,安裝好之後網址列旁邊會多一顆地球的按鈕。然後點擊地球 -> Options -> 到Import/Export頁面 -> Restore from File -> 載入剛剛goagent資料夾裡的local資料夾裡的SwitchyOptions.bak,如下圖所示



ps: 日本VPN