Pushmeup is an attempt to create an push notifications center that could send push to devices like:
- Android
- iOS
- Mac OS X
- Windows Phone
- And many others
Currently we have only support for iOS
and Android
but we are planning code for more plataforms.
$ gem install pushmeup
or add to your Gemfile
gem 'pushmeup'
and install it with
$ bundle install
- In Keychain access export your certificate and your private key as a
p12
.
![Keychain Access](https://raw.github.com/NicosKaralis/pushmeup/master/Keychain Access.jpg)
-
Run the following command to convert the
p12
to apem
file$ openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts
-
After you have created your
pem
file. Set the host, port and certificate file location on the APNS class. You just need to set this once:APNS.host = 'gateway.push.apple.com' # gateway.sandbox.push.apple.com is default APNS.port = 2195 # this is also the default. Shouldn't ever have to set this, but just in case Apple goes crazy, you can. APNS.pem = '/path/to/pem/file' # this is the file you just created APNS.pass = '' # Just in case your pem need a password
device_token = '123abc456def'
APNS.send_notification(device_token, 'Hello iPhone!' )
APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
device_token = '123abc456def'
n1 = APNS::Notification.new(device_token, 'Hello iPhone!' )
n2 = APNS::Notification.new(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default')
APNS.send_notifications([n1, n2])
APNS.send_notification(device_token, :alert => 'Hello iPhone!', :badge => 1, :sound => 'default',
:other => {:sent => 'with apns gem', :custom_param => "value"})
this will result in a payload like this:
{"aps":{"alert":"Hello iPhone!","badge":1,"sound":"default"},"sent":"with apns gem", "custom_param":"value"}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Register with apple that this app will use push notification
...
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge)];
...
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Show the device token obtained from apple to the log
NSLog("deviceToken: %", deviceToken);
}
GCM.host = 'https://android.googleapis.com/gcm/send'
# https://android.googleapis.com/gcm/send is default
GCM.format = :json
# :json is default and only available at the moment
GCM.key = "123abc456def"
# this is the apiKey obtained from here https://code.google.com/apis/console/
destination = ["device1", "device2", "device3"]
# can be an string or an array of strings containing the regIds of the devices you want to send
data = {:key => "value", :key2 => ["array", "value"]}
# must be an hash with all values you want inside you notification
GCM.send_notification( destination )
# Empty notification
GCM.send_notification( destination, data )
# Notification with custom information
GCM.send_notification( destination, data, :collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false )
# Notification with custom information and parameters
for more information on parameters check documentation: GCM | Android Developers
destination1 = "device1"
destination2 = ["device2"]
destination3 = ["device1", "device2", "device3"]
# can be an string or an array of strings containing the regIds of the devices you want to send
data1 = {:key => "value", :key2 => ["array", "value"]}
# must be an hash with all values you want inside you notification
options1 = {:collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false}
# options for the notification
n1 = GCM::Notification.new(destination1, data1, options1)
n2 = GCM::Notification.new(destination2, data2)
n3 = GCM::Notification.new(destination3, data3, options2)
GCM.send_notifications( [n1, n2, n3] )
# In this case, every notification has his own parameters
for more information on parameters check documentation: GCM | Android Developers
Check this link GCM: Getting Started
You can use multiple keys to send notifications, to do it just do this changes in the code
GCM.key = { :key1 => "123abc456def", :key2 => "456def123abc" }
# the ``:key1`` and the ``:key2`` can be any object, they can be the projectID, the date, the version, doesn't matter.
# The only restrain is: they need to be valid keys for a hash.
# For single notification
GCM.send_notification( destination, :identity => :key1 )
# Empty notification
GCM.send_notification( destination, data, :identity => :key1 )
# Notification with custom information
GCM.send_notification( destination, data, :collapse_key => "placar_score_global", :time_to_live => 3600, :delay_while_idle => false, :identity => :key1 )
# Notification with custom information and parameters
# For multiple notifications
options1 = {}
options2 = {..., :identity => :key2}
n1 = GCM::Notification.new(destination1, data1, options1.merge({:identity => :key2}))
n2 = GCM::Notification.new(destination2, data2, :identity => :key1)
n3 = GCM::Notification.new(destination3, data3, options2)
GCM.send_notifications( [n1, n2, n3] )
# In this case, every notification has his own parameters, options and key
We would be very pleased if you want to help us!
Currently we need a lot of testing so if you are good at writing tests please help us
Pushmeup is released under the MIT license: