diff --git a/README.textile b/README.textile index 6a9cc7fd..f0e8384f 100644 --- a/README.textile +++ b/README.textile @@ -203,6 +203,16 @@ h2. Example (assuming you have created an app and stored your keys on it): >> notification.save +h3. Using custom hashes for the alert block + +In the above example, it's also possible to replace the static alert text with a hash as outlined in the Apple documentation: + +
+ >> notification.alert = { 'loc-key' => 'LocalizedString.Key' }.to_json
+
+
+h2. Delivery
+
You can use the following Rake task to deliver your individual notifications:
diff --git a/lib/apn_on_rails/app/models/apn/notification.rb b/lib/apn_on_rails/app/models/apn/notification.rb
index 068f13a8..acb423d4 100644
--- a/lib/apn_on_rails/app/models/apn/notification.rb
+++ b/lib/apn_on_rails/app/models/apn/notification.rb
@@ -51,7 +51,13 @@ def alert=(message)
def apple_hash
result = {}
result['aps'] = {}
- result['aps']['alert'] = self.alert if self.alert
+ if self.alert
+ begin
+ result['aps']['alert'] = JSON.parse(self.alert)
+ rescue JSON::ParserError => e
+ result['aps']['alert'] = self.alert
+ end
+ end
result['aps']['badge'] = self.badge.to_i if self.badge
if self.sound
result['aps']['sound'] = self.sound if self.sound.is_a? String