iOSã¢ããªãé·æéããã¯ã°ã©ãŠã³ãã«çœ®ãããšã¯ã§ããŸããã ããããªé»åãç¯çŽããããã«ãããã¯ã°ã©ãŠã³ãã§å®è¡ãããŠããã¢ããªã±ãŒã·ã§ã³ã¯ãéãããã¢ã¯ã·ã§ã³ã»ãããå®è¡ã§ããŸãã
ããããã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠããªãå Žåã§ããäœãé¢çœãããšãèµ·ããããŠãŒã¶ãŒã«éç¥ãããå Žåã¯ã©ãã§ããããïŒ
ããšãã°ããŠãŒã¶ãŒãTwitterã§å¿çãåãåã£ãããæ°ã«å ¥ãã®ããŒã ãã²ãŒã ã«åã£ãããŸãã¯ã©ã³ãã®æºåãã§ããŠãããªã©ã§ãã ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããŠããªãããããã®ããŒã¿ã確èªããã³åä¿¡ã§ããŸããã
幞ããªããšã«ãAppleã¯ãã®åé¡ã®è§£æ±ºçãæäŸããŸããã ã€ãã³ããç¶ç¶çã«ãã§ãã¯ããããããã¯ã°ã©ãŠã³ãã§ã¢ã¯ã·ã§ã³ãå®è¡ããããã代ããã«ããããã®ã¢ã¯ã·ã§ã³ãå®è¡ããã¢ããªã±ãŒã·ã§ã³ã®ãµãŒããŒåŽãäœæã§ããŸãã
é¢å¿ã®ããã€ãã³ããçºçãããšããµãŒããŒåŽã¯ã¢ããªã±ãŒã·ã§ã³ã«ããã·ã¥éç¥ãéä¿¡ã§ããŸãïŒ ããã·ã¥éç¥ã§ã¯ã次ã®3ã€ã®ããšãã§ããŸãã
- çãããã¹ãã¡ãã»ãŒãžã衚瀺ããŸãã
- çãããŒãé³ã鳎ãããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã¢ã€ã³ã³ã®ãããžã«çªå·ãèšå®ããŸãã
å¿ èŠã«å¿ããŠãããã®ã¢ã¯ã·ã§ã³ãçµã¿åãããããšãã§ããŸãã ããšãã°ããµãŠã³ããåçããŠãããžã«çªå·ãèšå®ããŸãããã¡ãã»ãŒãžã¯è¡šç€ºããŸããã
çãã¬ãã¥ãŒ
ããã·ã¥éç¥ã¡ã«ããºã ã®æäœã¹ããŒã ïŒ
ã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ããŒã«ãããšãããã·ã¥éç¥ã®åãå ¥ãã確èªãããããã¢ããã¡ãã»ãŒãžã衚瀺ãããŸãã
- iOSã¯ãApple Push Notification ServiceïŒAPNSïŒãµãŒããŒã«ããã€ã¹ããŒã¯ã³ãèŠæ±ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã¯ããã€ã¹ããŒã¯ã³ãåãåããŸãã ããŒã¯ã³ã¯ããã·ã¥éç¥ãéä¿¡ããããã®ã¢ãã¬ã¹ã§ãããšæ³å®ã§ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã¯ããã€ã¹ããŒã¯ã³ããµãŒããŒã«éä¿¡ããŸãã
- ã¢ããªã±ãŒã·ã§ã³ã§ã€ãã³ããçºçãããšããµãŒããŒã¯ããã·ã¥éç¥ãAPNSã«éä¿¡ããŸãã
- APNSã¯ããã·ã¥éç¥ããŠãŒã¶ãŒã®ããã€ã¹ã«éä¿¡ããŸãã
ãŠãŒã¶ãŒãããã·ã¥éç¥ãåä¿¡ãããšãã¡ãã»ãŒãžã衚瀺ãããé³å£°ä¿¡å·ãåçãããã¢ããªã±ãŒã·ã§ã³ã¢ã€ã³ã³ã®ãããžãæŽæ°ãããŸãã ãŠãŒã¶ãŒã¯éç¥ããã¢ããªã±ãŒã·ã§ã³ãéãããšãã§ããŸãã ã¢ããªãããã·ã¥éç¥ã³ã³ãã³ããåä¿¡ããŠââåŠçã§ããããã«ããŸãã
iOS 4.0ã§ããŒã«ã«éç¥ãšãã«ãã¿ã¹ã¯ã衚瀺ãããå Žåãããã·ã¥éç¥ãåŒãç¶ã䜿çšããå¿ èŠããããŸããïŒ ã§ãããããã®ã«ïŒ
ããŒã«ã«éç¥ã¯æéå¶éã®ããã€ãã³ãã§ãã VOIPã¢ããªã±ãŒã·ã§ã³ãããã²ãŒã·ã§ã³ãããã³ããã¯ã°ã©ãŠã³ããµãŠã³ãã®åçã®ã¿ããç¡å¶éã®ããã¯ã°ã©ãŠã³ãå®è¡ãå¯èœã§ãã å€éšã€ãã³ããïŒéããŠããéã«ïŒã¢ããªã±ãŒã·ã§ã³ã®ãŠãŒã¶ãŒã«éç¥ããå¿ èŠãããå Žåãããã·ã¥éç¥ã䜿çšããå¿ èŠããããŸãã
ãã®ã¬ã€ãã§ã¯ãããã·ã¥éç¥ã·ã¹ãã ã®æäœãšããããã¢ããªã±ãŒã·ã§ã³ã«çµ±åããæ¹æ³ã«ã€ããŠè©³ãã説æããŸãã
ããã·ã¥éç¥ã«å¿ èŠãªãã®
ããã·ã¥éç¥ãã¢ããªã±ãŒã·ã§ã³ã«çµ±åããã«ã¯ã以äžãè¡ãå¿ èŠããããŸãã
iPhoneãiPadããŸãã¯iPod touchã ããã·ã¥éç¥ã¯ã·ãã¥ã¬ãŒã¿ãŒã§ã¯æ©èœããªãããããã¹ãã«ã¯ããã€ã¹ãå¿ èŠã§ãã
iOSéçºè ããã°ã©ã ã«ç»é²ããŸãã ããã·ã¥éç¥ã¡ã«ããºã ãçµ±åãããåã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠãæ°ããApp IDãšããããžã§ãã³ã°ãããã¡ã€ã«ãããã³ãµãŒããŒã®SSL蚌ææžãäœæããå¿ èŠããããŸãã ãããã®ã¢ã¯ã·ã§ã³ã¯ãiOSããããžã§ãã³ã°ããŒã¿ã«ã§å®è¡ãããŸãã
ãã®ã¬ã€ãã®äŸãå®å šã«å®è¡ããå Žåã¯ãããããžã§ãã³ã°ãããã¡ã€ã«ãšSSL蚌ææžãäœæããå¿ èŠããããŸãã ãããè¡ãæ¹æ³ã詳现ã«èª¬æããŸãã
ã€ã³ã¿ãŒãããã«æ¥ç¶ããããµãŒããŒã ããã·ã¥éç¥ã¯åžžã«ãµãŒããŒã«ãã£ãŠéä¿¡ãããŸãã éçºããã»ã¹äžã«ããµãŒããŒãšããŠç¬èªã®Macã䜿çšã§ããŸããããªãªãŒã¹ã«ã¯VPSïŒVirtual Private ServerïŒãªã©ãå¿ èŠã§ãã
ããã·ã¥éç¥ã䜿çšããã«ã¯ãå®äŸ¡ãªå ±æãã¹ãã£ã³ã°ã§ã¯äžååã§ãã ãµãŒããŒã§ããã¯ã°ã©ãŠã³ãå®è¡ãå®è¡ããSSL蚌ææžãã€ã³ã¹ããŒã«ããç¹å®ã®ããŒãã§çºä¿¡TLSæ¥ç¶ãæ§æããå¿ èŠããããŸãã ã»ãšãã©ã®å ±æãã¹ãã£ã³ã°ãããã€ããŒã¯ãããèš±å¯ããŸããã ãã¯ãã«ã«ãµããŒãã«é£çµ¡ãããšããã¹ãŠã®åé¡ã解決ã§ããå¯èœæ§ãé«ããªããŸãã ããã§ããVPSã䜿çšããããšã匷ããå§ãããŸãã
ããã·ã¥éç¥ã®æ§é
ãµãŒããŒã¯ãããã·ã¥éç¥çšã®ã¡ãã»ãŒãžãäœæãã責任ããããŸãã ãããã£ãŠããããã®ã¡ãã»ãŒãžãã©ã®ããã«èŠããããç¥ãããšã¯æçšã§ãã
ããã·ã¥éç¥ã¯ãããã€ã¹ããŒã¯ã³ããã€ããŒããããã³ãã®ä»ã®æ å ±ã§æ§æãããçãã¡ãã»ãŒãžã§ãã ãã€ããŒãã¯ãããã€ã¹ã«éä¿¡ãããå®éã®ããŒã¿ã§ãã
ãµãŒããŒã¯ãã€ããŒããJSONèŸæžã«å€æããå¿ èŠããããŸãã åçŽãªããã·ã¥ã¡ãã»ãŒãžã®ãã€ããŒãã¯æ¬¡ã®ãšããã§ãã
{ "aps": { "alert": "Hello, world!", "sound": "default" } }
äžæ¬åŒ§ã§å²ãŸãããããã¯ã«ã¯ãããŒãšå€ã®ãã¢ã§æ§æãããèŸæžãå«ãŸããŸãïŒNSDictionaryãšåãïŒã
ãã€ããŒãã¯ãå°ãªããšã1ã€ã®ããŒãšå€ã®ãã¢ãapsãã§æ§æãããèŸæžã§ããããã®æå³èªäœãèŸæžã§ãã äžèšã®äŸã§ã¯ããapsãã«ã¯ãalertããšãsoundãã®2ã€ã®ãã£ãŒã«ããå«ãŸããŠããŸãã ããã€ã¹ã«ããã·ã¥éç¥ãå±ããšããHelloãworldïŒããšããããã¹ããå«ããããã¢ããã¡ãã»ãŒãžã衚瀺ãããæšæºã®é³å£°ä¿¡å·ãåçãããŸãã
ããã«ããapsãã§ã¯ãä»ã®ãã£ãŒã«ããè¿œå ããŠéç¥ãæ§æã§ããŸãã äŸïŒ
{ "aps": { "alert": { "action-loc-key": "Open", "body": "Hello, world!" }, "badge": 2 } }
ããã§ãã¢ã©ãŒããã£ãŒã«ãã®å€ã¯èŸæžã«ãªããŸããã ãAction-loc-keyãã«ã¯ããRunããã¿ã³ã®ä»£æ¿ããã¹ããå«ãŸããŠããŸãã ãããžãã£ãŒã«ãã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã¢ã€ã³ã³ã®ãããžã«è¡šç€ºãããçªå·ãå«ãŸããŠããŸãã ããã·ã¥éç¥ã«ã¯é³å£°ä¿¡å·ã¯å«ãŸããŸããã
JSONãã€ããŒããçæããæ¹æ³ã¯ããªããããŸãã éç¥é³ãå€æŽããç¬èªã®ãã£ãŒã«ããè¿œå ã§ããŸãã 詳现ã«ã€ããŠã¯ãApple Developersãµã€ãã®ãããŒã«ã«ããã³ããã·ã¥éç¥ããã°ã©ãã³ã°ã¬ã€ããããŒãžãåç §ããŠãã ããã
ããã·ã¥éç¥ã¯ãããããã§ãã ãã€ããŒããµã€ãºã¯256ãã€ããè¶ ããããšã¯ã§ããŸããã ããã¯ãSMSãŸãã¯ãã€ãŒãã«å¯Ÿå¿ã§ããã®ãšã»ãŒåãã§ãã ããã·ã¥ãµãŒããŒã¯ãæ¹è¡ãã¹ããŒã¹ã«ç¡é§ã«ãªããŸãããã次ã®ãããªãã®ãçæããŸãã
{"aps":{"alert":"Hello, world!","sound":"default"}}
ãã®ãããªãã¬ãŒã³ããŒã·ã§ã³ã¯èªã¿ã«ãããªããŸããããã䟡å€ã®ããæ å ±ã®ããã«ååãªã¹ããŒã¹ãæäŸããŸãã APNSã¯ã256ãã€ããè¶ ããããã·ã¥éç¥ãæåŠããŸãã
ããã·ã¥éç¥ã«ã€ããŠ
圌ãã¯ä¿¡é Œã§ããŸããïŒ APNSãããããåãå ¥ãããšããŠããããã·ã¥éç¥ãé ä¿¡ãããä¿èšŒã¯ãããŸããã
ãµãŒããŒãããã·ã¥éç¥ãçæãããšãå¿çãªãã§ãããAPNSã«éä¿¡ããŸãã éä¿¡åŸã«ãšã³ããŠãŒã¶ãŒãžã®éç¥ã®é ä¿¡ã¹ããŒã¿ã¹ã確èªããæ¹æ³ã¯ãããŸããã é éæéã¯æ°ç§ãã30åãŸã§ããŸããŸã§ãã
ããã«ãiããã€ã¹ã®ãŠãŒã¶ãŒã¯ãåžžã«ããã·ã¥éç¥ãåä¿¡ã§ããªãå ŽåããããŸãã ããšãã°ãè¿ãã«ã€ã³ã¿ãŒãããã«ã¢ã¯ã»ã¹ã§ããWi-Fiãããã¯ãŒã¯ããªãããããã€ã¹ã®é»æºãå®å šã«ãªãã«ãªã£ãŠããå¯èœæ§ããããŸãã
APNSã¯ãããã€ã¹ãåä¿¡å¯èœã«ãªã£ããšãã«éä¿¡ãããæåŸã®éç¥ãé ä¿¡ããããšããŸãã ãããããããã®è©Šã¿ã«ã¯æéãéãããŠããŸãã ã¿ã€ã ã¢ãŠãåŸãããã·ã¥éç¥ã¯æ°žä¹ ã«å€±ãããŸãïŒ
圌ãã¯é«äŸ¡ã«ãªãå¯èœæ§ããããŸãïŒ ããŒã¿ãææããŠããå Žåãã¢ããªã±ãŒã·ã§ã³ã«ããã·ã¥æ©èœãè¿œå ããã®ã¯éåžžã«ç°¡åã§å®äŸ¡ã§ãã ãã ããå€æ°ã®ãŠãŒã¶ãŒãããå ŽåããŸãã¯ããŒã¿ãèŠæ±ããå¿ èŠãããå Žåãã³ã¹ãã¯æ¥æ¿ã«å¢å ããŸãã
ããšãã°ãRSSãã£ãŒãã®å€æŽããŠãŒã¶ãŒã«ç°¡åã«éç¥ã§ããŸããããã¯ããã£ãŒããå¶åŸ¡ããå€æŽããã€è¡ããããïŒãµã€ãã®ã³ã³ãã³ããæŽæ°ããããšãïŒãç¥ã£ãŠããããããµãŒããŒãå³åº§ã«éç¥ãéä¿¡ããããã§ãã
ããããã¢ããªã±ãŒã·ã§ã³ããŠãŒã¶ãŒããã£ãŒãã®URLãå ¥åã§ããRSSãªãŒããŒã§ããå Žåã¯ã©ãã§ããããïŒ ãã®å Žåãè¿œå ãããããŒããæŽæ°ããããã®è¿œè·¡ã¡ã«ããºã ãèãåºãå¿ èŠããããŸãã
å®éã«ã¯ãããã¯ããµãŒããŒããã£ãŒãã®å€æŽãåžžã«ãã§ãã¯ããå¿ èŠãããããšãæå³ããŸãã å€ãã®ãŠãŒã¶ãŒãããå Žåããã¹ãŠã®ããã»ã¹ãåŠçããå®å®ãã垯åå¹ ãç¶æããããã«è¿œå ã®ãµãŒããŒãã€ã³ã¹ããŒã«ããå¿ èŠãããå ŽåããããŸãã RSSãªãŒããŒãªã©ã®ã¢ããªã±ãŒã·ã§ã³ã®å Žåãããã·ã¥æ©èœã¯éåžžã«ã³ã¹ãããããããã䟡å€ããããŸããã
ããããŸãããååãªçè«ã ããããã¹ãŠã®ããã·ã¥ãå®è£ ããããã»ã¹ãåŠã¶æãæ¥ãŸããã ããããæããããããããã®ã«çæããåã«-ããã°ã©ãã³ã°ïŒ -iOS Provisioning Portalã§éå±ãªèšå®ãè¡ãå¿ èŠããããŸãã ããŠãå¯èœãªéãé«éã«ããŸãããã
ããããžã§ãã³ã°ãããã¡ã€ã«ãšèšŒææž
ããã·ã¥éç¥ãã¢ããªã±ãŒã·ã§ã³ã«æ¥ç¶ããã«ã¯ãé©åã«æ§æãããããããžã§ãã³ã°ãããã¡ã€ã«ã§çœ²åããå¿ èŠããããŸãã ããã«ããµãŒããŒã¯SSL蚌ææžã䜿çšããŠAPNSã«æ¥ç¶ããå¿ èŠããããŸãã
ããããžã§ãã³ã°ãããã¡ã€ã«ãšSSL蚌ææžã¯äºãã«å¯æ¥ã«é¢é£ããŠããã1ã€ã®ã¢ããªIDã«å¯ŸããŠã®ã¿æå¹ã§ãã ããã¯ããµãŒããŒã®ã¿ãã¢ããªã±ãŒã·ã§ã³ã®ãŠãŒã¶ãŒã«ããã·ã¥éç¥ãéä¿¡ã§ãããšããã»ãã¥ãªãã£ä¿èšŒã§ãã
ãåç¥ã®ããã«ãã¢ããªã±ãŒã·ã§ã³ã¯éçºãšãªãªãŒã¹ã«ç°ãªãããããžã§ãã³ã°ãããã¡ã€ã«ã䜿çšããŸãã ãµãŒããŒã®ããã·ã¥èšŒææžã«ã¯2ã€ã®ã¿ã€ãããããŸãã
- éçºã ã¢ããªã±ãŒã·ã§ã³ããããã°ã¢ãŒãã§ãéçºçšã®ããããžã§ãã³ã°ãããã¡ã€ã«ã«ãã£ãŠçœ²åãããŠããå ŽåïŒã³ãŒã眲åID-ãiPhoneéçºè ãïŒã
- ãªãªãŒã¹ïŒçç£ïŒã ã¢ãããã¯ãšããŠäœæãããã¢ããªã±ãŒã·ã§ã³ããŸãã¯App Storeã§ã®ããŠã³ããŒãã®æºåïŒã³ãŒã眲åèå¥-ãiPhoneé åžãïŒã¯ããªãªãŒã¹çšã®èšŒææžïŒè£œå蚌ææžïŒã䜿çšããŠããããšããµãŒããŒã«éç¥ããå¿ èŠããããŸãã ãããã®éã«ççŸãããå Žåãããã·ã¥éç¥ã¯ã¢ããªã±ãŒã·ã§ã³ã«å±ããŸããã
ãã®ã¬ã€ãã§ã¯ãéçºèšŒææžã®ã¿ã䜿çšããŸãã
蚌ææžçœ²åèŠæ±ïŒCSRïŒã®çæ
iOSéçºè ããã°ã©ã ã«åå ããåŸãã©ã®ããã«iOSããããžã§ãã³ã°ããŒã¿ã«ã«ã¢ã¯ã»ã¹ããéçºèšŒææžãäœæãããèŠããŠããŸããïŒ æ¬¡ã®æé ãåæ§ã§ãã ããããããã§ãã以äžã§èª¬æãããšããã«æ£ç¢ºã«å®è¡ããããšããå§ãããŸãã éçºè ã¯ã蚌ææžã«é¢é£ããããã·ã¥éç¥ã«é¢ããåé¡ã®ã»ãšãã©ãæ±ããŠããŸãã
ããžã¿ã«èšŒææžã¯ãå ¬ééµãšç§å¯éµã䜿çšããæå·åã«åºã¥ããŠããŸãã 蚌ææžã䜿çšããå Žåãæå·åã«ã€ããŠäœãç¥ãå¿ èŠã¯ãããŸãããã蚌ææžã¯åžžã«ç§å¯éµãšãã¢ã«ãªã£ãŠããããšã«æ³šæããå¿ èŠããããŸãã
蚌ææžã¯ããã®ããŒãã¢ã®äžè¬çãªéšåã§ãã ç§å¯éµã¯ç§å¯ã«ããŠããå¿ èŠããããŸãã ããªãã ãããããææããä»ã®èª°ãããã«ã¢ã¯ã»ã¹ããã¹ãã§ã¯ãããŸããã ç§å¯éµãªãã§èšŒææžã䜿çšããããšã¯äžå¯èœã§ãã
ããžã¿ã«èšŒææžãèŠæ±ãããã³ã«ããã®çœ²åãèŠæ±ããå¿ èŠããããŸãïŒèšŒææžçœ²åèŠæ±[CSR]ïŒã CSRãäœæãããšãæ°ããããŒãããŒãã§ãŒã³ã«å ¥åãããŸãã 次ã«ãCSRã蚌ææ©é¢ïŒãã®å Žåã¯iOSéçºè ããŒã¿ã«ïŒã«éä¿¡ããå¿ èŠããããŸãããã®æ©é¢ã¯ãCSRããã®æ å ±ã«åºã¥ããŠSSL蚌ææžãçæããŸãã
ãããŒãã§ãŒã³ããŠãŒãã£ãªãã£ïŒãã¢ããªã±ãŒã·ã§ã³âãŠãŒãã£ãªãã£ïŒãã®ä»ïŒãïŒãéãããèªèšŒå±ãã蚌ææžãèŠæ±ãã...ããªãã·ã§ã³ãéžæããŸãã
ãã®ã¡ãã¥ãŒãªãã·ã§ã³ã衚瀺ãããªãå ŽåããŸãã¯ãããŒã䜿çšããŠèªèšŒå±ã«èšŒææžãèŠæ±ããããšããããã¹ããå«ãã¡ãã»ãŒãžã衚瀺ãããå Žåã¯ã WWDRäžé蚌ææžãããŠã³ããŒãããŠã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã ãŸããç§å¯éµãå²ãåœãŠãããŠããªãããšã確èªããå¿ èŠããããŸãã
ããã§ãèªèšŒã¢ã·ã¹ã¿ã³ããŠã£ã³ããŠã衚瀺ãããŸãã
ããã«ã¡ãŒã«ãå ¥åããŠãã ããã éçºè ã¯ãiOSéçºè ããã°ã©ã ã«é»åã¡ãŒã«ãšããŠç»é²ããããã«äœ¿çšããã®ãšåãé»åã¡ãŒã«ã¢ãã¬ã¹ã䜿çšããããšããå§ãããŸãããããã¯å¿ é ã§ã¯ãããŸããã
å ±éåã«ã¯ããPushChatããšå ¥åããŸãã äœã§ãå ¥åã§ããŸããããããããããã®ãéžæããŠãã ããã åŸã§ããã«ãããç§å¯éµãç°¡åã«èŠã€ããããšãã§ããŸãã
[ãã£ã¹ã¯ã«ä¿å]ã©ãžãªãã¿ã³ãéžæãã[ç¶è¡]ãã¯ãªãã¯ããŸãã ãã¡ã€ã«ããPushChat.certSigningRequestããšããŠä¿åããŸãã
ã¢ããªIDãšSSL蚌ææžãäœæãã
iOSããããžã§ãã³ã°ããŒã¿ã«ã«ãã°ã€ã³ããŸãã
ãŸããæ°ããã¢ããªIDãäœæããŸãã ããã·ã¥éç¥ã¡ã«ããºã ã䜿çšããåã¢ããªã±ãŒã·ã§ã³ã«ã¯ãç¬èªã®äžæã®IDãå¿ èŠã§ãã
ãµã€ãããŒã®ãã¢ããªIDãé ç®ãã¯ãªãã¯ããŠããæ°ããã¢ããªIDããã¿ã³ãã¯ãªãã¯ããŸãã
次ã®ããã«ãã£ãŒã«ãã«å ¥åããŸããã
説æïŒPushChat
ãã³ãã«ã·ãŒãIDïŒããã©ã«ã
ãã³ãã«èå¥åïŒme.evgeniy.PushChat
ç§ã®ä»£ããã«ç¬èªã®ãã³ãã«èå¥å-com.yoursite.PushChat-ãæå®ããæ¹ãè¯ãã§ãããã Xcodeãããžã§ã¯ãã§ã¯ãåããã³ãã«IDãèšå®ããå¿ èŠããããŸãã
ããã«ããã€ãã®ãã€ã³ãïŒããã·ã¥ãµãŒããŒãAPNSã«å®å šã«æ¥ç¶ããããã«äœ¿çšããSSL蚌ææžãçæããŸãã ãã®èšŒææžã¯ã¢ããªIDã«é¢é£ä»ããããŠããŸãã ãµãŒããŒã¯ãã¢ããªã±ãŒã·ã§ã³ã«ã®ã¿ããã·ã¥éç¥ãéä¿¡ã§ããä»ã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯éä¿¡ã§ããŸããã
ã¢ããªIDãäœæããããšããªã¹ãã«è¡šç€ºãããŸãïŒ
ãããã·ã¥éç¥ãã®å察åŽã®ãéçºãåãšãçç£ãåã«ã¯ããæ§æå¯èœããšããèšèãä»ãã2ã€ã®ãªã¬ã³ãžè²ã®åããããŸãã ã€ãŸããã¢ããªIDã¯ããã·ã¥éç¥ã䜿çšã§ããŸãããèšå®ããå¿ èŠããããŸãã ãããã£ãŠããæ§æããªã³ã¯ãã¯ãªãã¯ããŠãã ããã
衚瀺ãããããŒãžã§ããAppleããã·ã¥éç¥ãµãŒãã¹ãæå¹ã«ãããã®æšªã®ããã¯ã¹ããªã³ã«ããŸãã 次ã«ãéçºããã·ã¥SSL蚌ææžã®è¡ã«ãã[æ§æ]ãã¿ã³ãã¯ãªãã¯ããŸãã ãAppleããã·ã¥éç¥ãµãŒãã¹SSL蚌ææžã¢ã·ã¹ã¿ã³ãããŠã£ã³ããŠãéããŸãã
æåã«è¡ãããšã¯ã蚌ææžçœ²åèŠæ±ãçæããããšã§ãã ããã¯ãã§ã«å®äºããŠããããã[ç¶è¡]ãã¯ãªãã¯ããŸãã
次ã®ã¹ãããã¯ãCSRãAppleãµãŒããŒã«ã¢ããããŒãããããšã§ãã åã«çæããCSRãã¡ã€ã«ãéžæãããçæããã¯ãªãã¯ããŸãã
SSL蚌ææžã®çæã«ã¯æ°ç§ããããŸãã æºåãã§ãããã[ç¶è¡]ãã¯ãªãã¯ããŸãã
蚌ææžãããŠã³ããŒãããã«ã¯ããããŠã³ããŒãããã¯ãªãã¯ããŸãããaps_development.cerããšããååã§ä¿åãããŸãã ãå®äºããã¯ãªãã¯ããåŸã
ããã§æå¹ãªèšŒææžãäœæãããããã·ã¥éç¥ã¡ã«ããºã ãéçºã«å©çšå¯èœã«ãªããŸããã å¿ èŠã«å¿ããŠã蚌ææžãå床ããŠã³ããŒãã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®ãªãªãŒã¹æºåãã§ããããããã»ã¹å šäœãç¹°ãè¿ããŠå®çšŒå蚌ææžãçæããå¿ èŠããããŸãã ãã¹ãŠã®æé ã¯äŒŒãŠããŸãã
çºèšã å®å蚌ææžã¯1幎éæå¹ã§ãããç· ãåãåã«åäœæã§ããŸãã
ããŒãã§ãŒã³ã«èšŒææžãè¿œå ããå¿ èŠã¯ãããŸããã ãããè¡ãå Žåã¯ã以åã«ããŠã³ããŒãããaps_development.cerãã¡ã€ã«ãããã«ã¯ãªãã¯ããŸãïŒãã®åŸã蚌ææžã¯ç§å¯éµã«é¢é£ä»ããããŸãïŒã
ããããžã§ãã³ã°ãããã¡ã€ã«ã®äœæ
ããããžã§ãã³ã°ããŒã¿ã«ãã芧ãã ããã [ããããžã§ãã³ã°]ãªã³ã¯ãã¯ãªãã¯ãã[æ°ãããããã¡ã€ã«]ãã¿ã³ãã¯ãªãã¯ããŸãã
次ã®ããã«ãã£ãŒã«ãã«å ¥åããŸããã
- ãããã¡ã€ã«åïŒPushChat Development
- 蚌ææžïŒèšŒææžãéžæããŸã
- ã¢ããªIDïŒPushChat
- ããã€ã¹ïŒããã€ã¹ãéžæããŸã
ãã®ããã»ã¹ã¯ãä»ã®ããããžã§ãã³ã°ãããã¡ã€ã«ã®çæãšåãã§ãã ããã·ã¥éç¥ã¡ã«ããºã ããµããŒãããåã¢ããªã±ãŒã·ã§ã³ã¯ãç¹å®ã®ã¢ããªIDã«é¢é£ä»ããããç¬èªã®ãããã¡ã€ã«ãå¿ èŠãšãããããæ°ãããããã¡ã€ã«ãäœæããŸãã
[éä¿¡]ãã¯ãªãã¯ãããšããããã¡ã€ã«ãçæãããŸãã æ°ãããããã¡ã€ã«ã¯ãä¿çäžãã«èšå®ãããŸãã ããŒãžããªããŒãããŠãã¹ããŒã¿ã¹ããã¢ã¯ãã£ããã«å€æŽãããããšã確èªããŸãã ããã§ãããããžã§ãã³ã°ãããã¡ã€ã«ïŒãPushChat.mobileprovisionããšãããã¡ã€ã«ïŒãããŠã³ããŒãã§ããŸãã
ãã¡ã€ã«ãIDEã¢ã€ã³ã³ã«ãã©ãã°ãããããã¡ã€ã«ãããã«ã¯ãªãã¯ããŠãããããžã§ãã³ã°ãããã¡ã€ã«ãXcodeã«è¿œå ããŸãã
ã¢ããªã±ãŒã·ã§ã³ããªãªãŒã¹ããæºåãã§ããããäžèšã®ããã»ã¹ãç¹°ãè¿ããŠãã¢ãããã¯ãŸãã¯App Storeã®é åžãããã¡ã€ã«ãäœæããå¿ èŠããããŸãã
ã·ã³ãã«ãªã¢ããª
åã®ã¢ã¯ã·ã§ã³ã¯æ¬åœã«ãšããµã€ãã£ã³ã°ã§ã¯ãããŸããã§ããããå®è¡ããå¿ èŠããããŸãã éçºè ã¯ãã®ãããªããšãæ¯æ¥è¡ããã蚌ææžããªããšããã·ã¥éç¥ãæ©èœããªãããã蚌ææžãçæããæ¹æ³ã詳现ã«ç€ºããããšæããŸããã
次ã«ãããã·ã¥éç¥ãåä¿¡ããåçŽãªã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã
Xcodeãéããæ°ãããããžã§ã¯ããäœæããŸãã ã¢ã·ã¹ã¿ã³ãã§ãã·ã³ã°ã«ãã¥ãŒã¢ããªã±ãŒã·ã§ã³ããéžæãã次ã®æé ã«é²ã¿ãŸãã
次ã®ããã«ãã£ãŒã«ãã«å ¥åããŸããã
- 補ååïŒPushChat
- äŒç€Ÿèå¥åïŒme.evgeniy
- ã¯ã©ã¹ã®ãã¬ãã£ãã¯ã¹ïŒPC
- ããã€ã¹ãã¡ããªïŒiPhone
- ãã§ãã¯ããã¯ã¹ïŒã¹ããŒãªãŒããŒãã䜿çšããèªååç §ã«ãŠã³ãã䜿çšãã
補ååãšäŒç€Ÿèå¥åãäžç·ã«ãªã£ãŠãã³ãã«IDã圢æããŸãã ç§ã®å Žåããme.evgeniy.PushChatãã§ãã ããããžã§ãã³ã°ããŒã¿ã«ïŒcom.yourname.PushChatïŒã§ä»¥åã«äœæãããã¢ããªIDã«å¯Ÿå¿ãã補ååãšäŒç€Ÿèå¥åãå ¥åããå¿ èŠããããŸãã
ãããžã§ã¯ããäœæããããPCAppDelegate.mãéããŸãã didFinishLaunchingWithOptionsã¡ãœããã次ã®ããã«å€æŽããŸãã
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // iOS 7 [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; // iOS 8 // [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; // [[UIApplication sharedApplication] registerForRemoteNotifications]; return YES; }
registerForRemoteNotificationTypesåŒã³åºãã¯ããã®ã¢ããªã±ãŒã·ã§ã³ãããã·ã¥éç¥ãåä¿¡ããããšãiOSã«éç¥ããŸãã
ã¢ããªã±ãŒã·ã§ã³ããã«ãããŠå®è¡ããŸãã ãããè¡ãã«ã¯ãã·ãã¥ã¬ãŒã¿ãããã·ã¥éç¥ããµããŒãããŠããªããããããã€ã¹ã䜿çšããå¿ èŠããããŸãã Xcodeã¯æ°ããããããžã§ãã³ã°ãããã¡ã€ã«ãèªåçã«éžæããŸãã ã¢ããªã±ãŒã·ã§ã³ã®èµ·åäžã«ãšã©ãŒãçºçããå Žåã¯ãã³ãŒã眲åIDã§æ£ãããããã¡ã€ã«ãéžæãããŠããããšã確èªããŠãã ããã
ã¢ããªã±ãŒã·ã§ã³ãèµ·åãããšãããã·ã¥éç¥ã®åãå ¥ãã確èªããã¡ãã»ãŒãžã衚瀺ãããŸãã
ã¢ããªã±ãŒã·ã§ã³ã¯èš±å¯ãäžåºŠã ãèŠæ±ããŸãã ãŠãŒã¶ãŒããOKããã¯ãªãã¯ãããšããã·ã¥éç¥ãå±ãããæåŠããããšããã·ã¥éç¥ãå±ããŸããã èšå®ã§æ±ºå®ãå€æŽã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã®ååãããã·ã¥éç¥èšå®ã«è¿œå ãããŸãã ããã§ããŠãŒã¶ãŒã¯ã¢ããªã±ãŒã·ã§ã³ã®ããã·ã¥éç¥ãæå¹ãŸãã¯ç¡å¹ã«ãããããããžããµãŠã³ããã¡ãã»ãŒãžãåå¥ã«èšå®ãããã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ã¯ãæå¹ã«ãªã£ãŠããããã·ã¥éç¥ã®ã¿ã€ããå€å¥ã§ããŸãã
UIRemoteNotificationType enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
ããã·ã¥éç¥ãåä¿¡ã§ããããã«ããã«ã¯ãã¢ããªã±ãŒã·ã§ã³ã«ãã1ã€è¿œå ããå¿ èŠããããã®ããããŸãã 次ã®ã³ãŒããPCAppDelegate.mã«è¿œå ããŸãã
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"My token is: %@", deviceToken); } - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { NSLog(@"Failed to get token, error: %@", error); }
ã¢ããªã±ãŒã·ã§ã³ãããã·ã¥éç¥ãåä¿¡ããããã«ç»é²ãããšãããã€ã¹ããŒã¯ã³ã®ååŸãè©Šè¡ãããŸãã ããã¯ãããã€ã¹ãäžæã«èå¥ãã32ãã€ãã®äžæã®çªå·ã§ãã ããã€ã¹ããŒã¯ã³ã¯ãããã·ã¥éç¥ã®éä¿¡å ã¢ãã¬ã¹ãšæ¯èŒã§ããŸãã
ã¢ããªã±ãŒã·ã§ã³ãèµ·åãããšãããã€ã¹ã®ããŒã¯ã³ãXcodeã³ã³ãœãŒã«ã«è¡šç€ºãããŸãã
My token is: <740f4707 bebcf74f 9b7c25d4 8e335894 5f6aa01d a5ddb387 462c7eaf 61bb78ad>
ããŒã¯ã³ã¯ãNSDataåã®ãªããžã§ã¯ãã§ããäžéæãªãã€ããªããŒã¿æ§é ã§ãã ãã®ç®çã®ããã«ã¯ã32ãã€ãã®ããã€ã¹ããŒã¯ã³ãç¥ã£ãŠããã ãã§ååã§ãã ããŒã¯ã³ã¯ã64æ¡ã®16é²æåãšããŠè¡šãããšãã§ããŸãã ãã®ãããªåœ¢åŒã䜿çšããŸãã
ã·ãã¥ã¬ãŒã¿ãŒã§ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããšãdidFailToRegisterForRemoteNotificationsWithErrorïŒã¡ãœãããåŒã³åºãããŸãããã®ã¡ãœããã¯ãã·ãã¥ã¬ãŒã¿ãŒãããã·ã¥éç¥ããµããŒãããŠããªããšããæ å ±ãå«ããšã©ãŒã衚瀺ããŸãã
ããã§ã¢ããªã±ãŒã·ã§ã³ã®äœæã¯å®äºã§ãã ã§ã¯ãããã·ã¥éç¥ãå®éã«è©ŠããŠã¿ãŸãããïŒ
ããã·ã¥éç¥ãéä¿¡ãã
åã«èª¬æããããã«ãããã·ã¥éç¥ãéä¿¡ããããã«ãµãŒããŒãæ§æããå¿ èŠããããŸãã ãã ãããã¹ãã«ã¯ãMac OS PushMeBabyçšã®ã¢ããªã±ãŒã·ã§ã³ã䜿çšããŸããããã¯ã githubãµãŒãã¹ããããŠã³ããŒãããããšãã§ããŸãã
ãã®åŸããã¹ãŠãç°¡åã§ã-Xcodeã§PushMeBabyãéãã以åã«äœæããSSL蚌ææžïŒaps_development.cerïŒããããžã§ã¯ãã«è¿œå ããApplicationDelegate.mãã¡ã€ã«ã®ç·šéã«é²ã¿ãŸãã initã¡ãœããã§ã次ã®å€æŽãè¡ããŸãã
ããã€ã¹ããŒã¯ã³ãè¿œå ããŸããããã¯ã以åã«äœæããã¢ããªã±ãŒã·ã§ã³ãèµ·åããåŸã«Xcodeã³ã³ãœãŒã«ã«è¡šç€ºãããŸãã
self.deviceToken = @"564f77d3 c1d06866 77a907d5 31d0450a 9cb552ec 5e2373e5 f2cc2c20 ff013232";
åè¿°ã®ãã€ããŒããè¿œå ããŸãïŒåŒçšç¬Šã¯å¿ ããšã¹ã±ãŒãããŠãã ããïŒã
self.payload = "{\"aps\":{\"alert\":\"Hello, world!\",\"sound\":\"default\"}}";
ãããŠããããžã§ã¯ãã«è¿œå ãããSSL蚌ææžã®ååãèšå®ããŸãã
self.certificate = [[NSBundle mainBundle] pathForResource:@"aps_development" ofType:@"cer"];
ããã§ã¢ããªã±ãŒã·ã§ã³ãèµ·åããããã·ã¥ãã¿ã³ãã¯ãªãã¯ããŸãã æ°ç§ä»¥å ã«ããã·ã¥éç¥ãåãåãã¯ãã§ãã
ãããŒã¹ã¿ã€ã«ã§ã¯ãããã·ã¥éç¥ã¯æ¬¡ã®ãšããã§ãã
ããªãã€ã³ããŒãã®ã¹ã¿ã€ã«ã§ã¯ããã身è¿ãªãã®ã§ãã
çºèšã ã¢ããªã±ãŒã·ã§ã³ãå®è¡ãããããã€ã¹äžã§ã¢ã¯ãã£ãã«ãªã£ãŠããå Žåãéç¥ã¯è¡šç€ºãããŸããã ãã ãããã€ããŒãã¯ã¢ããªã±ãŒã·ã§ã³ã«å±ããdidReceiveRemoteNotificationã¡ãœããã䜿çšããŠåŠçã§ããŸãã
- (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { NSLog(@"Received notification: %@", userInfo); }
ããã ãã§ã èå³ã®ãã質åã¯ãã¹ãŠã³ã¡ã³ãã§å°ããããšãã§ããŸãã ç§ã¯ãããã«çããããšããŸãã