Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support hashes for the 'alert' field #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 7 additions & 1 deletion lib/apn_on_rails/app/models/apn/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down