Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

support hashes for the 'alert' field #40

Open
wants to merge 1 commit into from

1 participant

@ened

This adds support for custom alert hashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +10 −0 README.textile
  2. +7 −1 lib/apn_on_rails/app/models/apn/notification.rb
View
10 README.textile
@@ -203,6 +203,16 @@ h2. Example (assuming you have created an app and stored your keys on it):
>> notification.save
</pre></code>
+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:
+
+<pre><code>
+ >> notification.alert = { 'loc-key' => 'LocalizedString.Key' }.to_json
+</pre></code>
+
+h2. Delivery
+
You can use the following Rake task to deliver your individual notifications:
<pre><code>
View
8 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
Something went wrong with that request. Please try again.