加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

从Ruby On Rails发送IOS推送通知

发布时间:2020-12-17 02:40:50 所属栏目:百科 来源:网络整理
导读:我需要向 IOS mobile发送推送通知. 我使用apn_on_rails发送此通知. 我从IOS开发者处获取了我的pem文件. 我做了以下配置 在Productions在config / configtran / * .rb中进行开发 RAILS_ROOT,APN::App::RAILS_ENV='production'configatron.apn.passphrase = 'l
我需要向 IOS mobile发送推送通知.

我使用apn_on_rails发送此通知.

我从IOS开发者处获取了我的pem文件.
我做了以下配置

在Productions&在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')

然后我按照文档创建了一个Notificationby.

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

从控制台

APN :: App.send_notifications

用耙子
???????RAILS_ENV =生产rake apn:通知:交付

我在生产和开发环境中都尝试过这种方法.
?在下面的行之后,它没有响应.我也没有在Log中找到任何东西.

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

我没有在任何云服务器上托管此应用程序.此应用程序是否应该在任何云服务器中托管以正确使用应用程序?

任何帮助赞赏.

解决方法

使用 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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读