更好的方法是使用UrbanAirship Groupon 版本。他们的文档非常清楚地指定了每一件事,并且代码会更整洁。在我的应用程序中工作和测试。
从自述文件中,(还有更多评论和所有):-
注意:如果您使用的是 Ruby 1.8,您还应该安装 system_timer gem 以获得更可靠的超时行为。有关详细信息,请参阅http://ph7spot.com/musings/system-timer。百里
gem install system_timer
安装
gem install urbanairship
# or specify in your gem file
gem "urbanairship"
配置在初始化目录中定义所有这些,然后确保您重新启动您的应用程序。
Urbanairship.application_key = 'application-key'
Urbanairship.application_secret = 'application-secret'
Urbanairship.master_secret = 'master-secret'
Urbanairship.logger = Rails.logger
Urbanairship.request_timeout = 5 # default
用法
注册设备令牌
Urbanairship.register_device 'DEVICE-TOKEN' # => true
注销设备令牌
Urbanairship.unregister_device 'DEVICE-TOKEN' # => true
发送推送通知(对于即时交付删除 schedule_for 属性)
notification = {
:schedule_for => 1.hour.from_now,
:device_tokens => ['DEVICE-TOKEN-ONE', 'DEVICE-TOKEN-TWO'],
:aps => {:alert => 'You have a new message!', :badge => 1}
}
Urbanairship.push notification # => true
批量推送通知发送(对于即时交付删除 schedule_for 属性)
notifications = [
{
:schedule_for => 1.hour.from_now,
:device_tokens => ['DEVICE-TOKEN-ONE', 'DEVICE-TOKEN-TWO'],
:aps => {:alert => 'You have a new message!', :badge => 1}
},
{
:schedule_for => 3.hours.from_now,
:device_tokens => ['DEVICE-TOKEN-THREE'],
:aps => {:alert => 'You have a new message!', :badge => 1}
}
]
Urbanairship.batch_push notifications # => true
发送广播通知 Urbanairship 允许您向您的应用程序的所有活动注册设备令牌发送广播通知。(对于即时交付删除 schedule_for 属性)
notification = {
:schedule_for => 1.hour.from_now,
:aps => {:alert => 'Important announcement!', :badge => 1}
}
Urbanairship.broadcast_push notification # => true