wireframe-apn_on_rails 0.3.0.20091216113551 → 0.3.0.20091216122815

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,10 +38,10 @@ module APN # :nodoc:
38
38
 
39
39
  # Raised when a notification message to Apple is longer than 256 bytes.
40
40
  class ExceededMessageSizeError < StandardError
41
-
41
+ MAX_BYTES = 255
42
42
  def initialize(message) # :nodoc:
43
- super("The maximum size allowed for a notification payload is 256 bytes: '#{message}'")
44
- @overage = message.size.to_i - 256
43
+ super("The maximum size allowed for a notification payload is #{MAX_BYTES} bytes: '#{message}'")
44
+ @overage = message.size.to_i - MAX_BYTES
45
45
  end
46
46
  def overage
47
47
  @overage
@@ -16,7 +16,6 @@
16
16
  # so as to not be sent again.
17
17
  class APN::Notification < APN::Base
18
18
  include ::ActionView::Helpers::TextHelper
19
- extend ::ActionView::Helpers::TextHelper
20
19
 
21
20
  serialize :payload
22
21
 
@@ -57,11 +56,12 @@ class APN::Notification < APN::Base
57
56
  end
58
57
 
59
58
  # Creates the binary message needed to send to Apple.
59
+ # see http://developer.apple.com/IPhone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingWIthAPS/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
60
60
  def message_for_sending
61
61
  json = self.to_apple_json
62
- message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
63
- raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
64
- message
62
+ raise APN::Errors::ExceededMessageSizeError.new(json) if json.size.to_i > APN::Errors::ExceededMessageSizeError::MAX_BYTES
63
+
64
+ "\0\0 #{self.device.to_hexa}\0#{(json.length).chr}#{json}"
65
65
  end
66
66
 
67
67
  class << self
@@ -98,10 +98,13 @@ class APN::Notification < APN::Base
98
98
  # Truncate alert message if message payload will be too long
99
99
  def truncate_alert
100
100
  return unless self.alert
101
- begin
102
- self.message_for_sending
103
- rescue APN::Errors::ExceededMessageSizeError => e
104
- self.alert = truncate(self.alert, :length => self.alert.size - e.overage)
101
+ while self.alert.length > 1
102
+ begin
103
+ self.message_for_sending
104
+ break
105
+ rescue APN::Errors::ExceededMessageSizeError => e
106
+ self.alert = truncate(self.alert, :length => self.alert.mb_chars.length - 1)
107
+ end
105
108
  end
106
109
  end
107
110
  end # APN::Notification
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wireframe-apn_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0.20091216113551
4
+ version: 0.3.0.20091216122815
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates