gcm_on_rails icon indicating copy to clipboard operation
gcm_on_rails copied to clipboard

Android push notification is not working..

Open asinghrails opened this issue 11 years ago • 6 comments

I am using this gem for sending push notification on android device (application users). This was working fine till 31st of december 2014 with response code(response = {:code=>200, :message=>nil}) after that this the notifications are not delivering to the user but I can see notifications on console.

ruby => ruby-1.9.3-p429 rails => rails', '3.2.14' gem => gcm_on_rails

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

Please help me and let me know that what is the issue with it.

asinghrails avatar Jan 16 '15 12:01 asinghrails

It works without any problem in my environment.

Would you check that your API key and Registration ID are correct really by other gems for GCM (e.g. https://github.com/spacialdb/gcm)?

kaosf avatar Jan 16 '15 16:01 kaosf

@kaosf Could you let me know that how are you using it so that i can make it usable for me. thanks.

asinghrails avatar Jan 17 '15 05:01 asinghrails

@asinghrails I'm using my forked repository because my project is Rails 4. But the diff between upstream/master and myrepos/master makes no change on sending HTTP request processs.

The difference is below https://github.com/kaosf/gcm_on_rails/compare/5c62586820ed9555d598d7707ce32cf15a2528c8...master

My usage of this gem is not special. Only create Gcm::Device and Gcm::Notification records and then call Gcm::Notification.send_notifications.

kaosf avatar Jan 17 '15 06:01 kaosf

@kaosf Thanks for this,

Please find my code and response.

class AndroidPushNotification def self.send_notification_to_user_android_device(resource, ride_id, notify_flag) device_ids = resource.user_device_ids.where(:device_type => 'Android').map(&:device_identifier) resource_name = resource.class.name == 'Driver' ? resource.first_name.titleize : resource.name.titleize notification_msg = notify_flag == 'new_ride_notification' ? 'you have a new ride request. Login and accept it now.' : 'you have a ride coming up in the next hour. Don't forget to click "On My Way" on the reservation page.' ride_data = notify_flag == "new_ride_notification" ? "1-" + "#{ride_id}" : "2-" + "#{ride_id}" unless device_ids.blank? device_ids.each do |device_id| puts "#################################" puts "notification start" device = Gcm::Device.find_or_create_by_registration_id(device_id.to_s)

    notification = Gcm::Notification.new
    notification.device = device
    notification.collapse_key = "updates_available"
    notification.delay_while_idle = true

    notification.data = {:registration_ids => [device_id], :data => {:message_text => resource_name + ', ' + notification_msg}, :ride_info => ride_data}
    notification.save!   

    puts "notification end"
    puts "#################################"
    Gcm::Notification.send_notifications
  end
end

end end

{:body=>"{"multicast_id":6244667542333363356,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"NotRegistered"}]}", :headers=>{"content-type"=>["application/json; charset=UTF-8"], "date"=>["Sat, 17 Jan 2015 06:23:56 GMT"], "expires"=>["Sat, 17 Jan 2015 06:23:56 GMT"], "cache-control"=> ["private, max-age=0"], "x-content-type-options"=>["nosniff"], "x-frame-options"=>["SAMEORIGIN"], "x-xss-protection"=>["1; mode=block"], "server"=>["GSE"], "alternate-protocol"=>["443:quic,p=0.02"], "accept-ranges"=>["none"], "vary"=>["Accept-Encoding"], "connection"=>["close"]}, :status_code=>200, :response=>"success", :canonical_ids=>[], :not_registered_ids=>["APA91bG6wXDgEBEot9ffsN64tQGdCYdRrtdggGCLTrv7Zla-fKtF31g97bt7-wfnJXeCnkSJxr-ahU_-mx_LLqi4D-LcFAmdHyzMftyzHT32alwmNUg2Ot5a14AP4saxJLGJ4TdnwzXIWpmBki1uKqb83nCWXOOOTsnfE66dVWeqgTR8VgT4GcQ"]}

Please help me that what i am missing in this code.

asinghrails avatar Jan 17 '15 06:01 asinghrails

Now issue has been fixed for me but messege is being sent nil.

asinghrails avatar Jan 17 '15 07:01 asinghrails

What was the issue @asinghrails ? I think I am also facing a similar issue

aelor avatar May 12 '15 15:05 aelor