Apple Push Notification Service
2010/06/07
-
Apple Push Notification Service
-
구성요소
- Alert - 메시지 출력을 위한 텍스트, App Name
- Badge ( icon ) - 아이콘 우측 상단에 생기는 붉은색 번호
( 보통, 읽지않은 글의 갯수 및 업데이트 가능 갯수 등등에 사용된다. ) - 버튼 - 한개 혹은 두개의 버튼을 구성할 수 있다.
- 사운드 - Push 알람 메시지 소리 설정. Default 사운드 설정
- notification = short message = device token + payload
- device token
- 클라이언트 어플리케이션이 설치된 device 의 위치를 APNs 가 인지하게 한다.
- notification 경로를 인증한다. - payload
- JSON 형태의 property list
- devie 상의 어플리케이션 유저에게 alerted 될것인가를 구체화 하기위한 데이터
-
특 징
- WIFI 는 iPod touch 이거나 3G망이 연결되지 않을 경우에만 Push Notifications 용도로 사용된다.
- WIFI로 Notification 을 받고 싶다면, 화면이 켜져 있거나, USB가 연결되어 있어야 한다.
- WIFI 송신은 TCP port 5223을 통해서만 외부로 나가게 된다.
-
provider 를 통해 client application에 push notification 이 도달되는 경로
- provider 와 APNS 사이( Gateway )에는 다중 경로가 될수 있다. ( provider 가 다양하기 때문 )
- 다양한 provider들에게서 다수의 device 에 notification 이 전달되는 경로
-
Feddback Service
- 개 요
- 몇몇 device의 경우 현재 App. 이 설치되어 있지 않아서( 삭제되어서 ) provider들이 APNs통해 전달한 notification 이 거절되는 경우가 있다. 이경우엔 APNs가 해당 provider에게 feedback 서비스를 통해 알려준다.
- 이렇게 알려진 정보들을 통해 provider들은 notification이 해당 device에 재전송되지 않도록 조치해야 한다.
- 개 요
-
Quality of Service ( QoS )
- 개요
- APNs는 저장 및 포워드 기능을 수행하는 기본적인 QoS 컴포넌트를 포함하고 있다.
- APNs는 notification을 전달하려는 deviece 가 offline 일 경우에는 QoS 는 해당 notification 을 저장한다. ( 각 device 별로 App.당 한개( 최종 전송한 )의 notification 만 저장한다. )
- QoS에 의해 제한 시간을 넘어선 notification 은 자동 삭제된다.
- 개요
-
Security Architecture
- 개요
- 통신을 위해선 provider와 device 간에 entry points 의 노출은 필수적이다. 보안을 위해, 이들 entry points간의 접근 통제는 필수적이다.
- APNs는 이들 provider와 device 의 통신상의 각각의 다른 두개의 신뢰 레벨을 가지고 있다. 접속 trust와, 토큰 trust가 그것이다. - Connection trust
- 접속중 APNs 접속은 애플이 notification 전달을 동의한 인증된 provider 에 의해서 제공된다.
- 접속중 APNs는 적합한 device와 함께한 커넥션에 대해서만 허가한다. - Token trust
- APNs 내부에서는 정확한 메시지 라우팅을 보장은 device token 을 통해서만 만들어진다.
- Device token : APNs에 처음으로 접속시 device 에 부여하는 보안된 인증값.
- 최소 APNs에 접속시 제공받은 device token 은 provider를 통해 각 notification이 수행될때마다 함께한다. - Service-to-Device Connection Trust
- Provider-to-Service Connection Trust
-
Token 의 생성 및 분산
- 아이폰 App.은 push notification 수신을 등록해야한다. 보통 device 에 설치될때 바로 수행된다.
- App.으로부터 등록 요청을 받게 되면 iPhone OS 는 APNs에 접속을 하고, 해당 요청을 포워드 한다.
- APNs는 Unique Device 인증을 포함한 정보를 사용하여 device token 을 생성한다.
- Device token 은 device의 식별 정보를 포함하고 있다.
- token key로 암호화된 device token 을 device로 돌려보내준다.
- device 는 돌려받은 device token App.에 보낸다.- App.은 다시 provider들에게 ( 16진수 형태로 되어 있고 ) device tokent을 전달해야 한다.
- Token Trust ( Notification )
- provider 가 APNs로 보내는 모든 notification은 device 내의 App.에 포함된 device token이 포함되어야 한다.
- APNs는 token key로 token 정보를 decrypt 하고, notification이 유효한지를 체크한다.
- device token에 포함되어 있는 device ID는 notification의 목적지 주소를 결정하는데 사용된다.
-
The Notification Payload
- 각각의 Push Notification 은 payload와 함께 전송된다.
- payload는 유저들에게 어떻게 client App.에 다운로드되기 위해 대기중인 데이터들을 알릴것인가를 정하게 된다.
- payload의 최대 사이즈는 256bytes 이다. 만일 초과한 데이터를 전송하면, APNs는 거부하게 된다.
- notification의 전달은 최선을 다하지만, 보장하지는 않는다는 것을 기억하라.
- 각 notification를 위해, provider들은 RFC4627에 명확히 명시한것처럼 JSON dictionay object 로 구성해야 한다.
- 이 dictionary 는 반드시 "aps" 키로 식별되는 또다른 dictionary를 포함해야 한다.
- aps dictionary 는 다음과 같은 사항을 포함해야 한다.- user에게 보여주기 위한 alert 메시지
- 배지 아이콘의 번호
- 실행할 sound
- notification이 도착했을때, 타겟 App.가 실행중이지 않다면 alert 메시지와, 사운드 배지 값을 출력 및 실행할것이다. 실행중이라면, iPhone OS는 타겟 App.에 NSDictionary object 로서 App.에 notification을 넘길 것이다.
Table 2-1 Keys and values of the apsdictionaryKey
Value type
Comment
alertstring or
dictionary
If this property is included, iPhone OS displays a standard alert. You may specify a string as the value of
alertor a dictionary as its value. If you specify a string, it becomes the message text of an alert with two buttons: Close and View. If the user taps View, the application is launched.Alternatively, you can specify a dictionary as the value of
alert. SeeTable 2-2for descriptions of the keys of this dictionary.badgenumber
The number to display as the badge of the application icon. If this property is absent, any badge number currently shown is removed.
soundstring
The name of a sound file in the application bundle. The sound in this file is played as an alert. If the sound file doesn’t exist or
defaultis specified as the value, the default alert sound is played. The audio must be in one of the audio data formats that are compatible with system sounds; see“Preparing Custom Alert Sounds”for detaiTable 2-2 Child properties of the alertpropertyKey
Value type
Comment
bodystring
The text of the alert message.
action-loc-keystring or
nullIf a string is specified, displays an alert with two buttons, whose behavior is described inTable 2-1. However, iPhone OS uses the string as a key to get a localized string in the current localization to use for the right button’s title instead of “View”. If the value is
null, the system displays an alert with a single OK button that simply dismisses the alert when tapped. See“Localized Formatted Strings”for more information.loc-keystring
A key to an alert-message string in a
Localizable.stringsfile for the current localization (which is set by the user’s language preference). The key string can be formatted with%@and%n$@specifiers to take the variables specified inloc-args. See“Localized Formatted Strings”for more information.loc-argsarray of strings
Variable string values to appear in place of
-
Localized Formatted Strings
- 2가지의 방식으로 Localized alert message 를 보여줄수 있다.
- 서버를 통한 localize
.. Device에 현재 선택된 언어 설정 정보를 참조할수 있다.
.. client App.는 지역화를 지원하기 위해 번역된 alert-message를 번들로 각각 저장할 수 있다.
.. provider 는 loc-key 및 loc-args 프로퍼티 형태로 notification payload 의 aps dictionary 내부에 지정할 수 있다.
.. Device( 현재 해당App.은 실행중이지 않다고 가정 ) 가 notification 을 받았을때, 이들 aps-dictionary 프로퍼티들을 현재 언어에 맞도록 localize된 문자열 형태의 포맷을 찾아서 사용한다. 그리고, 유저에게 출력한다.
- 좀더 자세히 설명하면 다음과 같다.
.. iOS ( iPhone OS ) 내부의 App.는 각각의 언어로된 이미지나 사운드, 텍스트와 같은 리소스를 국제화( internationalize ) 할 수 있고, 지원한다.
Internationalize는 리소스들을 수집하고, 두개의 이름( 예를 들면 fr.lproj )으로 분류된 이름의 형태로 번들( bundle : App이 설치된 폴더를 의미하는듯 )의 서브디렉토리안에 넣어둔다.
.. 프로그램형식처럼 구성된 Localized된 문자열들은 Localizeable.strings 로 불리는 파일안에 놓여진다.
.. 이 파일안의 각각의 엔트리들은 키와 로컬화된 문자열값들을 가지고 있다. ( Key and Value ) 문자열들은 변수형 값들을 대체하기 위한 포맷 특수문자들을 가질수 있다. ( sprintf 에서의 %s와 같은 구성처럼 )
.. App.에서 일부분의 리소스를 요청할때 - 지역화된 문자열을 말한다. - 유저에 의해 현재 선택된 언어의 지역화된 리소스를 얻을수 있다.
.. 예를 들면, 프랑스어로 언어가 제공되었다면, App. 번들안의 디렉토리에 위치한 fr.lproj 파일안의 Localizeable.strings 로부터 alert message내부의 그에 대응하는 문자열 값을 가져올수 있다.
( iOS는 이요청을 NSLocalizedString Macro를 통해 만든다. )
- 좀더 명확하게 하기 위해 예시를 보는게 좋겠다."alert" : { "loc-key" : "GAME_PLAY_REQUEST_FORMAT", "loc-args" : [ "Jenna", "Frank"] },.. GAME_PLAY_REQUEST_FORMAT 이 key가 되고, [ "Jenna", "Frank" ] 가 대체를 위한 값이 된다.
"GAME_PLAY_REQUEST_FORMAT" = "%@ and %@ have invited you to play Monopoly";.. 직관적으로 알수 있지만, Device가 notification을 받을때, 현재 언어의 dictionary 디렉토리인 .lproj안의 Localizable.strings 파일안에 연관된 문자열을 찾는데 "GAME_PLAY_REQUEST_FORMAT"을 키로 사용한다. 현재 Localization이 위와 같은 Localizable.strings 엔트리를 가진다고 가정하면, Device 는 "Jenna and Frank invited you to play Monopoly" 라는 alert message 를 출력한다.
.. %@에 추가적으로, %n$n라는 대체 위치를 포함한 포맷지시자를 사용할수가 있다. n ( 1로 시작하는 )은 대체를 위한 loc-args안의 배열 값을 의미한다. 하단 예시 참조. ( %는 %%로 표현할 수 있다. )"GAME_PLAY_REQUEST_FORMAT" = "%2$@ and %1$@ have invited you to play Monopoly";.. Device 는 "Frank and Jenna have invited you to play Monopoly"라는 alert message 를 출력한다.
- Examples of JSON Payloads
{"aps" : { "alert" : "Message received from Bob" },"acme2" : [ "bang", "whiz" ]}{ "aps" : { "alert" : { "body" : "Bob wants to play poker", "action-loc-key" : "PLAY" }, "badge" : 5, }, "acme1" : "bar", "acme2" : [ "bang", "whiz" ] }{"aps" : {"alert" : "You got your emails.","badge" : 9,"sound" : "bingbong.aiff"},"acme1" : "bar","acme2" : 42}
기억해야할 것은 notication 에 payload를 포함하기 전에 모든 whitespace 및 newline을 제거해주어야 한다는 것이다.{"aps" : {},"acme2" : [ 5, 8 ]}
- 개요
-
-
History
Last edited on 06/16/2010 09:08 by forder
Comments (0)