iphone - 使用 Urban AirShip 和 Rails 3 for iphone 推送通知

标签 iphone ruby-on-rails ios push-notification urbanairship.com

使用 Rails 3 网络应用程序通过 Urban AirShip 发送推送通知的最佳方式是什么?

来自 Urban Airship 文档:

An HTTP POST to /api/push/broadcast/ sends the given notification to all registered device tokens for the application. The payload is in JSON with content-type application/json, with this structure:

{
    "aps": {
         "badge": 15,
         "alert": "Hello from Urban Airship!",
         "sound": "cat.caf"
    },
    "exclude_tokens": [
        "device token you want to skip",
        "another device token you want to skip"
    ]
}

我真的不知道从哪里开始!

最佳答案

更好的方法是使用 UrbanAirship Groupon version .他们的文档非常清楚地指定了每一件事,并且代码会更加整洁。在我的应用程序中工作和测试。

来自自述文件(包含更多评论和所有内容):-

注意:如果您使用的是 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

用法

注册设备 token

    Urbanairship.register_device 'DEVICE-TOKEN' # => true

注销设备 token

    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 允许您向应用程序的所有事件注册设备 token 发送广播通知。(对于即时交付,删除 schedule_for 属性)

    notification = {
      :schedule_for => 1.hour.from_now,
      :aps => {:alert => 'Important announcement!', :badge => 1}
    }

    Urbanairship.broadcast_push notification # => true

关于iphone - 使用 Urban AirShip 和 Rails 3 for iphone 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6622495/

相关文章:

iphone - 我正在使用默认的 UITableViewCell 。我想从本地服务器在单元格上设置图像...cell.imageView.image

ruby-on-rails - 通过 ActiveResource 向 Web 服务提供凭据

ruby-on-rails - 在 RoR 中使用没有模式的 'new' 操作时 ActiveResource NoMethodError

iphone - 在 iPhone 中使用哪种方法从视频中提取帧?

ios - 如何在不更新应用程序的情况下更新 iPhone 应用程序中的新闻提要?

swift - 如何在 Xcode 中向 Google Maps API 添加叠加层

iphone - 检测 UITextView 何时完成滚动

iphone - MoreNavigationController 图像在选择时消失

ruby-on-rails - Rails 设置生产环境在本地机器上使用 SSL

ios - 更改 View 的父级