jirapong-apn_on_rails 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,10 +48,17 @@ class APN::Notification < APN::Base
48
48
  # apn.sound = true
49
49
  # apn.custom_properties = {"typ" => 1}
50
50
  # apn.apple_hash # => {"aps" => {"badge" => 0, "sound" => "1.aiff"}, "typ" => "1"}
51
+ # apn.alert = { 'loc-key' => 'LocalizedString.Key' }.to_json
51
52
  def apple_hash
52
53
  result = {}
53
54
  result['aps'] = {}
54
- result['aps']['alert'] = self.alert if self.alert
55
+ if self.alert
56
+ begin
57
+ result['aps']['alert'] = JSON.parse(self.alert)
58
+ rescue JSON::ParserError => e
59
+ result['aps']['alert'] = self.alert
60
+ end
61
+ end
55
62
  result['aps']['badge'] = self.badge.to_i if self.badge
56
63
  if self.sound
57
64
  result['aps']['sound'] = self.sound if self.sound.is_a? String
@@ -80,8 +87,8 @@ class APN::Notification < APN::Base
80
87
  # Creates the binary message needed to send to Apple.
81
88
  def message_for_sending
82
89
  json = self.to_apple_json
83
- c = "\0".encode('UTF-8')
84
- message = "#{c}#{c} #{self.device.to_hexa.force_encoding('UTF-8')}#{c}#{json.length.chr.force_encoding('UTF-8')}#{json.force_encoding('UTF-8')}"
90
+ c = "\0"
91
+ message = "#{c}#{c} #{self.device.to_hexa}#{c}#{json.length.chr}#{json}"
85
92
  raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
86
93
  message
87
94
  end
@@ -1,3 +1,3 @@
1
1
  module ApnOnRails
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jirapong-apn_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-06-16 00:00:00.000000000 Z
13
+ date: 2012-06-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: configatron