如何从rails应用程序发送c2dm消息
编辑 3
我使用 RhoMobile 获取 device_token,我正在将其发送到服务器
def register_device
@person = Person.find(:first)
unless System.get_property('is_emulator')
url = "#{@base}/users/#{@person.remote_id}/register_device?os=#{System.get_property('platform')}&device_token=#{System.get_property('device_id')}"
Rho::AsyncHttp.get(
:url => url,
:headers => {'User-Agent' => Rho::RhoConfig.user_agent}
)
end
finish_and_go_to_venue
end
编辑 2
有 device_token 但不断收到 Error=NotRegistered
编辑
好的,所以第一个错误是使用了错误的设备 ID。现在可以使用,但手机没有消息提醒。
原创
第一次从 Rails 服务器发送 android Push 消息的用户。
使用 https://github.com/sghael/speedy_c2dm
我向 Google 注册并收到白名单电子邮件。
尝试下面的 test.rb,但没有任何内容发送到手机。
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :development)
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'speedy_c2dm'
TEST_EMAIL = "[email protected]"
TEST_PASSWORD = "MY_PASSWORD"
TEST_REGISTRATION_ID = "DEVICE_TOKEN_RECEIVED_FROM_PHONE"
speedyC2DM = SpeedyC2DM::API.new(TEST_EMAIL, TEST_PASSWORD)
options = {
:registration_id => TEST_REGISTRATION_ID,
:message => "Hi!",
:extra_data => 42,
:collapse_key => "some-collapse-key"
}
response = speedyC2DM.send_notification(options)
EDIT 3
I use RhoMobile to get device_token, which I am getting to server
def register_device
@person = Person.find(:first)
unless System.get_property('is_emulator')
url = "#{@base}/users/#{@person.remote_id}/register_device?os=#{System.get_property('platform')}&device_token=#{System.get_property('device_id')}"
Rho::AsyncHttp.get(
:url => url,
:headers => {'User-Agent' => Rho::RhoConfig.user_agent}
)
end
finish_and_go_to_venue
end
EDIT 2
Have device_token but keep getting Error=NotRegistered
EDIT
OK, so first mistake was using the wrong device ID. Now working, but phone not alerting with message.
ORIGINAL
First time user of sending android Push messages from rails server.
Using https://github.com/sghael/speedy_c2dm
I registered with google and received white list email.
trying test.rb below, but nothing gets sent to phone.
require 'rubygems'
require 'bundler'
Bundler.setup(:default, :development)
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'speedy_c2dm'
TEST_EMAIL = "[email protected]"
TEST_PASSWORD = "MY_PASSWORD"
TEST_REGISTRATION_ID = "DEVICE_TOKEN_RECEIVED_FROM_PHONE"
speedyC2DM = SpeedyC2DM::API.new(TEST_EMAIL, TEST_PASSWORD)
options = {
:registration_id => TEST_REGISTRATION_ID,
:message => "Hi!",
:extra_data => 42,
:collapse_key => "some-collapse-key"
}
response = speedyC2DM.send_notification(options)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加一个名为 Push 的控制器,在控制器内您需要具有以下内容:
您需要通过将以下行添加到您的 application.rb 中来设置您的应用程序来调用它
此外,您是否配置了构建.yml 正确吗?
至少对于我的应用程序,我需要运行应用程序才能获取消息。
Try adding a Controller named Push and inside the controller you need to have the following:
you need to set your application to call this by adding the following line to your application.rb
Also, did you configure your build.yml correctly?
At least with my app, I need to have the application running in order to get the message.