bingo bob
2011-May-11 07:55 UTC
Constructing an array of stuff (to send multiple apple push notifications)
I''m using this gem https://github.com/justintv/APNS to send push notifications to an iPhone app and amazingly it works for single notifications, such that I can do... APNS.send_notification(Device.first.device_token,''test message'') Works great... Now it should be a simple task (as per the docs to send multiple notifications) Gem says like this... device_token = ''123abc456def'' n1 = [device_token, :aps => { :alert => ''Hello...'', :badge => 1, :sound => ''default'' } n2 = [device_token, :aps => { :alert => ''... iPhone!'', :badge => 1, :sound => ''default'' }] APNS.send_notifications([n1, n2]) ##### for me it''s slightly different, I wish to loop through each device in my db and then send the same message to them all...it''s something like this but it''s clearly not quite right... can''t get the :aps => thing to work out. I think I need something like this on my Device model, but it''s not right - please help correct it, would greatly appreciate. def self.push_message_to_all(message) devices = self.all notifications = [] devices.each do |device| notifications << [device.device_token,message] end APNS.send_notifications(notifications) end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2011-May-11 15:08 UTC
Re: Constructing an array of stuff (to send multiple apple push notifications)
Any ideas? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-May-11 15:19 UTC
Re: Constructing an array of stuff (to send multiple apple push notifications)
On 11 May 2011 08:55, bingo bob <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m using this gem https://github.com/justintv/APNS to send push > notifications to an iPhone app and amazingly it works for single > notifications, such that I can do... > > APNS.send_notification(Device.first.device_token,''test message'') > > Works great... > > Now it should be a simple task (as per the docs to send multiple > notifications) > > Gem says like this... > > device_token = ''123abc456def'' > n1 = [device_token, :aps => { :alert => ''Hello...'', :badge => 1, :sound > => ''default'' } > n2 = [device_token, :aps => { :alert => ''... iPhone!'', :badge => 1, > :sound => ''default'' }] > APNS.send_notifications([n1, n2])Have you tried that? It doesn''t look like valid ruby to me (even with the missing ] on the end of n1)> > ##### > > for me it''s slightly different, I wish to loop through each device in my > db and then send the same message to them all...it''s something like this > but it''s clearly not quite right... can''t get the :aps => thing to work > out. > > I think I need something like this on my Device model, but it''s not > right - please help correct it, would greatly appreciate. > > > > def self.push_message_to_all(message) > devices = self.all > notifications = [] > devices.each do |device| > notifications << [device.device_token,message] > endOnce you have got the manual example above working the use ruby-debug to break in here and have a look at notifications and see if it is of the same form as if you break into the manual test and look at it there. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2011-May-12 15:45 UTC
Re: Constructing an array of stuff (to send multiple apple push notifications)
Thanks Colin, I''ll give that a spin. The example code in the gem does seem odd. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Reasonably Related Threads
- Is it possible to enable push notifications for iOS/macOS mail clients on a stock dovecot?
- Is it possible to enable push notifications for iOS/macOS mail clients on a stock dovecot?
- Is it possible to enable push notifications for iOS/macOS mail clients on a stock dovecot?
- Frequently changing IP addresses
- Mocking objects to test Rails Controllers