LoginSignup
0
0

More than 5 years have passed since last update.

houstonでリッチ通知を送る

Last updated at Posted at 2016-12-31

※追記(2017/01/15)
2年弱くらいぶりにhoustonの新バージョンがリリースされたのでこの記事の内容は不要になりました🎉
https://github.com/nomad/houston/releases/tag/v2.2.4

houstonはiOSアプリにプッシュ通知を送るためのgemですが、iOS10からのリッチ通知を試す際にも使ったところ下記のようなエラーが出ました。

undefined method `mutable_content=' for #<Houston::Notification:0x007f90889efa50> (NoMethodError)

リッチ通知を送信するために必要なmutable-content: 1を含める部分でエラーになってるようです。

READMEの通りやったのになんぞ?

ということで見てみたらどうも「README含めていくつかの新機能がmasterに取り込まれているが、RubyGemsへのリリース等が行なわれていない」という状態になっていたためのようでした。

RubyGems上での最新バージョンはだいぶ昔の2015/01/29にリリースされた2.2.3で(2016/12/31現在)、README通りの下記のコマンドではこの古いバージョンのhoustonがインストールされてしまいます。

$ gem install houston

このバージョンではリッチ通知を送るためのmutable_contentをセットするためのメソッドがまだありません。

ということでhoustonの最新のmasterをインストールしましょう!

GitHubのリポジトリからgemをinstallする'specific_install'というgemを使って下記のようにインストールします。

$ gem install specific_install
$ gem specific_install -l 'https://github.com/nomad/houston.git'

$ gem list houston   // houston (2.2.4)

これで無事リッチ通知もhoustonから送れるようになりました!

require 'houston'

`Houston::Client.production`.
APN = Houston::Client.development
APN.certificate = File.read("./apple_push_notification.pem")

token = "<xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx>"

notification = Houston::Notification.new(device: token)
notification.alert = "落ち着つけ・・・\n『sushi』を数えて落ち着くんだ・・・"
notification.category = "myNotificationCategory"
notification.mutable_content = true

APN.push(notification)

(houstonもうリリースされないのかな・・・)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0