Browse files

Don't encode utf8 strings before sending to apple. This allows longer…

… messages
  • Loading branch information...
1 parent bea6a21 commit 16b33ebdcaa2975543e02fb7bdb948bb20becbdd @ramigg committed Mar 21, 2012
View
2 lib/apn_on_rails/app/models/apn/group_notification.rb
@@ -70,7 +70,7 @@ def to_apple_json
# Creates the binary message needed to send to Apple.
def message_for_sending(device)
- json = self.to_apple_json
+ json = self.to_apple_json.gsub!(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")} # This will create non encoded string. Otherwise the string is encoded from utf8 to ascii with unicode representation (i.e. \\u05d2)
message = "\0\0 #{device.to_hexa}\0#{json.length.chr}#{json}"
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message
View
2 lib/apn_on_rails/app/models/apn/notification.rb
@@ -79,7 +79,7 @@ def to_apple_json
# Creates the binary message needed to send to Apple.
def message_for_sending
- json = self.to_apple_json
+ json = self.to_apple_json.gsub!(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")} # This will create non encoded string. Otherwise the string is encoded from utf8 to ascii with unicode representation (i.e. \\u05d2)
message = "\0\0 #{self.device.to_hexa}\0#{json.length.chr}#{json}"
raise APN::Errors::ExceededMessageSizeError.new(message) if message.size.to_i > 256
message

0 comments on commit 16b33eb

Please sign in to comment.