Webã¢ããªãããPushéç¥ãï¼Chromeã®Pushéç¥ã«ã¤ãã¦
ãã¤ãã£ãã¢ããªã§ã¯å½ããåã¨ãªã£ããããã·ã¥éç¥ããï¼Chromeãããéããããã«ãªãã¾ããï¼Webã¢ããªãããããã·ã¥éç¥ãéããã¨ãªãï¼è©±é¡ã«ãªã£ã¦ãã¾ãï¼
æ©éåã試ãã¦ã¿ãã®ã§ï¼ä½¿ãæ¹ãã¾ã¨ãã¦ããã¾ãï¼
åä½ãµã³ãã«
ã¨ããããï¼ãµã³ãã«ãåããã¦ã¿ã¦ãã ããï¼
ãããã·ã¥éç¥ãåä¿¡ããããã¿ã³ãæ¼ãã¨ï¼ããã·ã¥éç¥ãåä¿¡ã§ããããã«ãªãã¾ãï¼
åæã«ï¼ãã¿ã³ã®ä¸ã«ã³ãã³ãã表示ãããã®ã§ï¼ããã端æ«ï¼ã¿ã¼ããã«ï¼ä¸ããå®è¡ããã¨ï¼ããã·ã¥éç¥ãéä¿¡ã§ãã¾ãï¼
éä¿¡ã«æåããã¨ï¼æ¬¡ã®ãããªã¡ãã»ã¼ã¸ã表示ããã¾ãï¼
{"multicast_id":<æ°å>,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"<æ°å>"}]}%
åæã«ï¼ããã·ã¥éç¥ã表示ãããã¨æãã¾ãï¼
èªåã§ããã·ã¥éç¥ãåããã¦ã¿ãï¼
注æï¼
- å®è¡ãããµã¼ããSSLéä¿¡ï¼https://~ï¼ã«å¯¾å¿ãã¦ããå¿ è¦ãããã®ã§ï¼æ³¨æãã¦ä¸ããï¼
- ã¾ãï¼Chromeã®ãã¼ã¸ã§ã³ã¯42以éã§ããå¿ è¦ãããã¾ãï¼ï¼ãã¹ã¯ãããçï¼Androidçããããï¼
ã½ã¼ã¹ã³ã¼ãã®DL
ä¸è¨ãµã³ãã«ã®ã½ã¼ã¹ã³ã¼ããGitHubããDLãã¾ãï¼
ããã¦ï¼ä»¥ä¸ã®ç®æãæ¸ãæãã¾ãï¼
main.js
3è¡ç®ã®
var API_KEY = '';
ã«ï¼API keyãå
¥åãã¾ãï¼
API keyã®åå¾æ¹æ³ã¯ä»¥ä¸ãåç
§ãã¦ä¸ããï¼
http://tech.vasily.jp/android_chrome_push/
service-worker.js
以ä¸ã®ãã¹ãï¼èªèº«ã®ç°å¢ã«ãããã¦å¤æ´ãã¦ä¸ããï¼
8è¡ç®ä»è¿
var icon = '/chrome-push-notification/images/icon.png';
38è¡ç®ä»è¿
return clients.openWindow('/chrome-push-notification/');
manifest.json
以ä¸ã®ãã¹ãï¼åæ§ã«èªèº«ã®ç°å¢ã«ãããã¦å¤æ´ãã¦ä¸ããï¼
icons
å ã®src
start_url
以ä¸ãå
¨ã¦å®äºãããï¼ãµã¼ãã«ã¢ãããã¼ããã¦ï¼index.htmlã«ã¢ã¯ã»ã¹ãã¦ã¿ã¦ãã ããï¼
ä¸è¨ãµã³ãã«ã¨åãããã«ããã°ï¼ãã¾ãåä½ãã¦ãã¾ãï¼
è£è¶³
å®éã«å°å ¥ããéã®æ³¨æç¹
ãã®ããã·ã¥éç¥ãå®éã«å°å ¥ããã¨ãªãã¨ï¼å¹¾ã¤ã解決ããªããã°ãªããªãåé¡ãããã¾ãï¼
subscription.subscriptionId
ããµã¼ãå´ã§ä¿æããå¿ è¦ãããï¼- ç¾ç¶ã§ã¯ããã·ã¥éç¥ã®å 容ã¯åºå®ã®ãã®ããéããªãï¼
1ã«é¢ãã¦ï¼ãã®ããã·ã¥éç¥ã®ä»çµã¿ã¨ãã¦ï¼ã¦ã¼ã¶ãããã·ã¥éç¥ãåä¿¡ãã許å¯ãããã¨ï¼subscription.subscriptionId
ãçºè¡ããã¾ãï¼ãµã¼ãå´ã§ã¯ï¼ãã®IDã«å¯¾ãã¦ããã·ã¥éç¥ãéä¿¡ãã¾ãï¼ãªã®ã§ï¼ãã®IDããµã¼ãå´ã§ä¿æãã¦ãããªããã°ï¼èå¿ã®ããã·ã¥éç¥ãéä¿¡ã§ãã¾ããï¼
ãµã¼ãå´ã§ä¿æããæ¹æ³ã¨ãã¦ã¯ï¼ãã¡ã¤ã«ã«ä¿åããï¼DBã«ä¿åãããªã©ãèãããã¾ãï¼ä¸è¨ãµã³ãã«ã§ã¯ï¼ãã¡ã¤ã«ã«ä¿åããã³ã¼ããæ¸ãã¦ããã®ã§ï¼ããã£ãã試ãã¦ã¿ã¦ãã ããï¼
ã¾ãï¼ãµã¼ãå´ã§ä¿æããIDã«å¯¾ãã¦ä¸æã«ããã·ã¥éç¥ãéä¿¡ããã«ã¯ï¼curlã³ãã³ãå
ã®registration_ids
ã«å¯¾ãã¦ï¼JSONã®é
åå½¢å¼ã§è¤æ°ã®IDãæå®ãã¦ããã ãã§ãï¼ä¾ãã°ï¼ä»¥ä¸ã®ãããªæãã§ãï¼
curl --header "Authorization: key=<API key>" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"<subscriptionId1>\", \"<subscriptionId2>\"]}"
2ã«é¢ãã¦ã¯ï¼ããã¯APIã対å¿ããã®ãå¾
ã¤ããããã¾ããï¼
ä¸å¿ï¼curlã³ãã³ãã®JSONé¨ã«data
ã¨ãããªãã¸ã§ã¯ãã追å ãããã¨ã§ï¼ä»»æã®ãã¼ã¿ãéä¿¡ãããã¨ã¯ã§ããããã§ããï¼ç¾ç¶ã§ã¯åä¿¡ãã§ããªãããã§ãï¼
curl --header "Authorization: key=<API key>" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"<subscriptionId1>\", \"<subscriptionId2>\"], \"data\":{\"title\":\"ã¿ã¤ãã«\",\"url\":\"URL\"}}"
ãããã°ã«ã¤ãã¦
ããã·ã¥éç¥ãé常ã«ãããã°ãã«ããã®ã§ããï¼ä¸å¿ãããªãã¼ã«ãChromeã«ç¨æããã¦ãã¾ãï¼
chrome://serviceworker-internals
å¤å°ã¯ãããã°ããããâ¦ããªï¼
åèãã¼ã¸
以ä¸ã®ãã¼ã¸ãåèã«ããã¦é ãã¾ããï¼
ããªãããããããè¨è¿°ããã¦ããã®ã§æ¯éä¸åº¦ã覧ãã ããï¼
http://tech.vasily.jp/android_chrome_push/
è±èªã§ããï¼ãã¡ããåèã«ãªãã¾ãï¼
ä½è«
GitHub Pages | Websites for you and your projects, hosted directly from your GitHub repository. Just edit, push, and your changes are live.ã£ã¦ä¾¿å©ã§ããï¼ããã·ã¥éç¥ã®ãµã³ãã«ãå
¬éããã®ã«ä½¿ç¨ãã¦ã¿ã¾ããï¼
æ¹æ³ã¯ä»¥ä¸ãåèã«ãªãã¾ãï¼