32
browser push notifications @kanayannet

Browser push notifications

Embed Size (px)

Citation preview

Page 1: Browser push notifications

browser push notifications

@kanayannet

Page 2: Browser push notifications

今日話すこと

1.push notificationって? 2.何故やろうと思ったか? 3.browser でどこまで可能? 4.実装方法 5.まとめ

Page 3: Browser push notifications

push notificationって?

push 通知の事です。

Page 4: Browser push notifications

何故やろうと思ったか?自作のアプリケーションで…

(植物の栽培日記)

記録のつけ忘れ や 水のやり忘れ を

push通知させたい!

Page 5: Browser push notifications

何故やろうと思ったか?

メールだと迷惑メール設定とか面倒だし… !

native アプリから push通知も手だけど… ブラウザで作った方が作りやすいし…

Page 6: Browser push notifications

browser でどこまで可能?3種類あった1. W3C push notification

2. Google Cloud Messaging for Chrome

3. safari push notifications

Page 7: Browser push notifications

browser でどこまで可能?W3C push notification

new Notification(‘hello world’,{!! ! ! ! ! ! ! ! ! ! ‘body': ‘body!’!! ! ! ! ! ! ! ! ! ! ! });

Page 8: Browser push notifications

browser でどこまで可能?

実はこれブラウザが開いてないと動きません。

W3C push notification

Page 9: Browser push notifications

これじゃない!!

Page 10: Browser push notifications

browser でどこまで可能?Google Cloud Messaging for Chrome

と思ったら…

Page 11: Browser push notifications

既にやり方が広く日本語で 公開されている…

Page 12: Browser push notifications

browser でどこまで可能?safari push notification

※ここから先の画像は apple社の公式ドキュメントを 引用しています。

Page 13: Browser push notifications

英語ドキュメントばかり.. これだ!!

Page 14: Browser push notifications

safari push notification

Page 15: Browser push notifications

電子証明書を取得する

safari push notification

Page 16: Browser push notifications

Push Package を用意する (zip ファイルにする)

safari push notification

Page 17: Browser push notifications

結構面倒くさい..safari push notification

Page 18: Browser push notifications

便利なライブラリがあります (grocer-pushpackager)

safari push notification

builder = Grocer::Pushpackager::Package.new({ websiteName: ‘farm-log', allowedDomains: [“https://farm-log.com”], iconSet: {:'16x16' => File.open('./icons/16x16.png'), ……… });

Page 19: Browser push notifications

※連携するライブラリに version依存 がいくつかあります。

safari push notification

version 0.0.1…

Page 20: Browser push notifications
Page 21: Browser push notifications

safari push notificationブラウザ<->サーバ間でやりとりするのは javascript で行う。

Page 22: Browser push notifications

safari push notification

これに成功すると…

Page 23: Browser push notifications

safari push notificationapple社に json データを送信する

Page 24: Browser push notifications

便利なライブラリがあります (grocer)

safari push notification

notification = Grocer::SafariNotification.new(! device_token: '...', ! title: 'Hello world',! body: 'こんにちわ世界', ! action: ‘読む',! url_args: [‘/’] !)!

Page 25: Browser push notifications

実際にやってみます

safari push notification

Page 26: Browser push notifications

失敗用画像です

safari push notification

Page 27: Browser push notifications

まとめW3C push notification

W3C の push通知 で動くのは local(ブラウザプロセス内) だけか? (金澤 が 知らないだけ?)

Page 28: Browser push notifications

まとめ

参考: https://developer.mozilla.org/

W3C push api というのがあるが…今のところ PC は全滅

Page 29: Browser push notifications

まとめ

参考: https://developer.mozilla.org/

firefox OS の firefoxは動くらしいが…

Page 30: Browser push notifications

まとめGoogle Cloud Messaging for Chrome

便利そう

やり方が日本語ドキュメントで公開中(@it) いずれ試してみたい

Page 31: Browser push notifications

まとめ

便利まだ日本語ドキュメント少ない !

でも訳せば行ける !

ライブラリも枯れてないけど(version 依存注意) あるよ

safari push notification

Page 32: Browser push notifications

ご清聴ありがとうございました