dondeng / gcm_on_rails

Gcm on Rails (Google Cloud Messaging for Android on Rails)
MIT License
79 stars 48 forks source link

gcm:notifications:deliver stops after delivering #7

Closed kruzel closed 12 years ago

kruzel commented 12 years ago

is there a way to continuously run gcm:notifications:deliver?

amal007 commented 12 years ago

You can set up a cronjob with this rake command "rake gcm:notifications:deliver" and set the cronjob to run every 1min to check continuously

or if you want to deliver the notification from the code

What I used is, Instead of calling the rake task when ever your want to send notification I call this method in the controller

Gcm::Notification.send_notifications

Sample code

      device_token = "12321321312"
      device = Gcm::Device.find_or_create_by_registration_id(:registration_id => "#{device_token}")
      notification = Gcm::Notification.new
      notification.device = device
      notification.collapse_key = "updates_available"
      notification.delay_while_idle = false
      notification.data = {:registration_ids => ["#{device_token}"], :data => {:message_text => "Message!!!!!"}}
      notification.save!
      Gcm::Notification.send_notifications
dondeng commented 12 years ago

Kruzel, amal's method above is the way to go.