1

I am new to rails and i wanted to know whether i would be able to change my existing server in rails to a 3rd party application server by adding the gem gcm_on_rails . I have installed the gem in this assumption and have pushed a message to the gcm server using the code in the console

   device = Gcm::Device.create(:registration_id =>"APA91bGJSaiKkCm_h9w8prWsL_inTMPs8pmCme8dcLpW0_2AKbny4bTXpx823cCfJLDJmO3_ihiww1ZVK0iqToAlPWKFWcBSraGRw6KNB1PsLYJJWvRZJ3bMP0")
   notification = Gcm::Notification.new
   notification.device = device
   configatron.gcm_on_rails.delivery_format = 'json'
   notification.collapse_key = "updates_available"
   notification.delay_while_idle = true
   notification.data = {:registration_ids => ["APA91bGJSaiKkCm_h9w8prWsL_inTMPs8pmCme8dcLpW0_2AKbny4bTXpx823cCfJLDJmO3_ihiww1ZVK0iqToAlPWKFWcBSraGRw6KNB1PsLYJJWvRZJ3bMP0"], :data => {:message_text => "Get on cloud nine"}}
   notification.save
   Gcm::Notification.send_notifications

and i am getting the response as

response = {:code=>200, :message=>nil}

but in the documentation of the above gem itself its said that even if the message=>nil is shown the message might have been send!

I am assuming that the message was send have also created an android application having the aforesaid registerid but also i am not getting any notification

A help on this scenario would be greatly appreciated

thank you

4

1 回答 1

0

我使用了宝石' gcm '。我发现通过 GCM 将数据发送到我的 android 应用程序会更好。它还具有近乎实时的响应。只需设置一个 Rails 服务器并在主目录中添加一个脚本,代码如下:

require 'gcm'
api_key = 'your-gcm-api-key'
gcm = GCM.new(api_key)
registration_ids= ["client_reg_id1","client_reg_id2"] # an array of reg ids of app clients
options = {"label"=>"data"}
response = gcm.send_notification(registration_ids, options)

启动 rails 服务器,然后使用从命令行运行此脚本ruby -rubygems script.rb,您就完成了。

于 2013-03-22T05:09:53.797 回答