问题描述
我有一个需要从服务器将通知发送到设备的项目。我不知道如何和从哪里开始(第一或其他创建表),因为我是新来的Ruby on Rails的。我跟着apn_sender教程,但它不会开始工作,总是错误的。有没有完全教程创建的Rails 3 apn_sender?
I have a project that needs to send notifications from server to device. I don't know how and where to start (create table first or other), because I'm new to Ruby on Rails. I've follow the apn_sender tutorial but it won't work and always errors out on start. Is there any full tutorial to create apn_sender for Rails 3?
感谢
推荐答案
我也一直在努力的apn_sender问题,因为我喜欢,苹果推送通知的支持似乎pretty强劲。然而,该项目已被放弃,现在它正在下降最近3系列导轨后面。我已经得到了系统的工作如下:
Rails 3 and apn_sender
I too have been working on the apn_sender problem, because I like that the Apple Push Notification support seems pretty robust. However, the project has been abandoned and now it is falling behind the latest 3 series rails. I have gotten the system working as follows.
gem 'apn_sender', :require => 'apn'
gem 'daemons'
gem 'resque', '1.20.0'
gem 'resque-access_worker_from_job'
信号处理中Resque改后1.20,所以你必须使用旧1.20.0。守护进程应该一直以来的要求,但从来没有明确在创业板上市规格。
The signal handling changed in Resque after 1.20 so you must use the older 1.20.0. Daemons should have been a requirement all along but was never explicitly in the gem spec.
#!/usr/bin/env ruby
# Daemons sets pwd to /, so we have to explicitly set RAILS_ROOT
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
require 'rubygems'
require 'apn'
require 'apn/sender_daemon'
APN::SenderDaemon.new(ARGV).daemonize
从这里是不会产生apn_sender剧本的原因是因为生成器脚本需要为3系列导轨进行更新。
Retrieved this from here. The reason the apn_sender script is not generated is because the generator script needs to be updated for 3 series rails.
./script/apn_sender --environment=production --verbose start
在启动环境的产值大概是因为你既ad_hoc想要什么,并正在使用的生产许可证发布的版本。
When starting the environment the production value is probably what you want since both ad_hoc and release versions are using the production certificate.
已经纠正了一些轨道的3个问题,但resque版本问题仍然需要明确地解决。
This fork on github has corrected some of the rails 3 issues, but the resque version problem still needs to be resolved explicitly.
的展示如何发送绕过守护进程的邮件。他存储标记为Base64 EN codeD字符串这是很好的,紧凑。在apn_sender框架的设备字符串的格式是格式化这样一个十六进制字符串: DEADBEEF 0a1b2cdf DEADBEEF 0a1b2cdf DEADBEEF 0a1b2cdf DEADBEEF 0a1b2cdf
。空间可选的。
This website shows how to send messages bypassing the daemon. He stores the tokens as base64 encoded strings which is nice and compact. The format of a device string in the apn_sender framework is a hex string formatted like this: deadbeef 0a1b2cdf deadbeef 0a1b2cdf deadbeef 0a1b2cdf deadbeef 0a1b2cdf
. Spaces optional.
require 'base64'
ios_device_token = User.where(username: 'Cameron').first.ios_device_token
token = Base64.decode64(ios_device_token).unpack('H*').first.scan(/\w{8}/).join(' ')
notification = APN::Notification.new(token, { alert: 'Hello, World!', sound: true, badge: 99 })
sender = APN::Sender.new(verbose: true, environment: 'production')
sender.send_to_apple(notification)
确保feedback.rb文件的内容保持最新
# Unpacking code borrowed from http://github.com/jpoz/APNS/blob/master/lib/apns/core.rb
while bunch = socket.read(38) # Read data from the socket
f = bunch.strip.unpack('N1n1H140')
feedback << APN::FeedbackItem.new(Time.at(f[0]), f[2])
end
在code的一个版本缺少38和它造成不好的令牌字符串从反馈服务返回
One version of the code lacked 38 and it resulted in bad token strings being returned from the feedback service
如果您打算服用Ruby开发到一个新的水平,你也应该考虑像一个IDE因为它使一切都那么容易多了。
If you plan on taking Ruby development to the next level you should also consider an IDE like RubyMine because it makes everything so much easier.
这篇关于apn_sender和Rails 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!