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