编辑 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
我在谷歌注册并收到了白名单电子邮件。
在下面尝试 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 = "my_push_email@gmail.com"
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)