Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed create_apn_notifications to add a custom_properties column

Changed notification.rb to use the custom properties of a notification in the hash for apple and to serialize the custom_properties field
  • Loading branch information...
commit 04cec0c05e5a292ef95749ace3229f47c9b0dd47 1 parent 71ee874
Rebecca Nesson authored markbates committed
View
1  generators/templates/apn_migrations/002_create_apn_notifications.rb
@@ -9,6 +9,7 @@ def self.up
t.string :sound
t.string :alert, :size => 150
t.integer :badge
+ t.text :custom_properties
t.datetime :sent_at
t.timestamps
end
View
14 lib/apn_on_rails/app/models/apn/notification.rb
@@ -17,6 +17,7 @@
class APN::Notification < APN::Base
include ::ActionView::Helpers::TextHelper
extend ::ActionView::Helpers::TextHelper
+ serialize :custom_properties
belongs_to :device, :class_name => 'APN::Device'
@@ -39,6 +40,13 @@ def alert=(message)
# apn.sound = 'my_sound.aiff'
# apn.alert = 'Hello!'
# apn.apple_hash # => {"aps" => {"badge" => 5, "sound" => "my_sound.aiff", "alert" => "Hello!"}}
+ #
+ # Example 2:
+ # apn = APN::Notification.new
+ # apn.badge = 0
+ # apn.sound = true
+ # apn.custom_properties = {"typ" => 1}
+ # apn.apple_hast # => {"aps" => {"badge" => 0}}
def apple_hash
result = {}
result['aps'] = {}
@@ -48,6 +56,11 @@ def apple_hash
result['aps']['sound'] = self.sound if self.sound.is_a? String
result['aps']['sound'] = "1.aiff" if self.sound.is_a?(TrueClass)
end
+ if self.custom_properties
+ self.custom_properties.each do |key,value|
+ result["#{key}"] = "#{value}"
+ end
+ end
result
end
@@ -90,6 +103,7 @@ def send_notifications(notifications = APN::Notification.all(:conditions => {:se
APN::Connection.open_for_delivery do |conn, sock|
notifications.each do |noty|
+ puts "\n\napple has is: #{noty.apple_hash}\n\n"
conn.write(noty.message_for_sending)
noty.sent_at = Time.now
noty.save
Please sign in to comment.
Something went wrong with that request. Please try again.