【问题标题】:Sending IOS Push Notifications from Ruby On Rails从 Ruby On Rails 发送 IOS 推送通知
【发布时间】:2015-04-26 01:36:57
【问题描述】:

我需要向 IOS 手机发送推送通知。

我使用 apn_on_rails 发送此通知。

我从 IOS 开发人员那里得到我的 pem 文件。 我在上面做了如下配置

在 config/configtran/*.rb 中的生产和开发中

RAILS_ROOT, APN::App::RAILS_ENV='production'
configatron.apn.passphrase  = 'leo_123'
configatron.apn.port  = 2195
configatron.apn.host  = 'gateway.sandbox.push.apple.com'
configatron.apn.cert = File.join(Rails.root, 'config', ' apple_push_notification_development.pem')

然后我按照文档创建了一个通知。

在我运行以下命令后,它是理想的并响应

从控制台

APN::App.send_notifications

使用耙子 RAILS_ENV=production rake apn:notifications:deliver

我在生产和开发环境中都尝试过。 在以下行之后,它没有响应。我也没有在 Log 中找到任何内容。

APN::App Load (0.1ms)  SELECT "apn_apps".* FROM "apn_apps"

我没有在任何云服务器中托管这个应用程序。此应用程序是否应托管在任何云服务器中才能正常运行该应用程序?

任何帮助表示赞赏。

【问题讨论】:

  • 你应该创建通知:github.com/PRX/…
  • 我已经创建了通知
  • 我认为在apn_on_rails 中您需要运行迁移。它使用数据库表。如果你不想要任何桌子,你可以使用 grocer gem。
  • 我为 apn_on _rails 运行了生产迁移。让我也检查一下杂货店的宝石

标签: ios ruby-on-rails ruby push-notification apple-push-notifications


【解决方案1】:

使用grocer gem 更容易。

pusher = Grocer.pusher(certificate: "#{Rails.root}/lib/dev_cert.pem", # required
                       passphrase:  "XXXXXX",                         # optional
                       gateway:     "gateway.sandbox.push.apple.com", # optional
                       port:        2195,                             #optional
                       retries:     3)

feedback = Grocer.feedback( certificate: "#{Rails.root}/lib/dev_cert.pem", 
                                  passphrase:  "XXXXXX",                        
                                  gateway:     "feedback.sandbox.push.apple.com", 
                                  port:        2196,                     
                                  retries:     3)

 notification = Grocer::Notification.new(
    device_token:      push_id,
    alert:             message,
    badge:             3,
    sound:             "siren.aiff",         # optional
    expiry:            Time.now + 60*60,     # optional; 0 is default, meaning the message is not stored
    # identifier:        1234,                 # optional
    content_available: true                  # optional; any truthy value will set 'content-available' to 1
  )

  feedback.each do |attempt|
    puts "Device #{attempt.device_token} failed at #{attempt.timestamp}"
  end

  pusher.push(notification)

【讨论】:

  • 请您再次发送通知
  • 您好,请发送通知,请分叉我的代码并合并您的代码,我的消息不会发送
  • 哈哈,我工作两天了,我需要你的帮助,请分享代码
  • 它返回的是数字,但我没有在设备中收到任何通知。你能从你这边发一份通知吗
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-28
  • 2017-12-07
  • 2015-05-17
  • 2014-03-27
  • 1970-01-01
相关资源
最近更新 更多