Skip to content

Commit

Permalink
Merge pull request #2 from althafh/multiple-apps
Browse files Browse the repository at this point in the history
Increase max size of notification payload to 2048 bytes
  • Loading branch information
Ryan Law committed May 11, 2015
2 parents 763eeba + 5cf7c13 commit 339b3af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/apn/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Notification
# Available to help clients determine before they create the notification if their message will be too large.
# Each iPhone Notification payload must be 256 or fewer characters (not including the token or other push data), see Apple specs at:
# https://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
DATA_MAX_BYTES = 255
DATA_MAX_BYTES = 2047

attr_accessor :options, :token
def initialize(token, opts)
Expand Down
12 changes: 6 additions & 6 deletions spec/apn/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
end
end

context "when payload is over 256 bytes" do
let(:payload) { "»" * 200 }
context "when payload is over 2048 bytes" do
let(:payload) { "»" * 2049 }

it "raises" do
expect {
Expand Down Expand Up @@ -106,7 +106,7 @@
end

context "when alert is a string" do
let(:payload) { "a" * 300 }
let(:payload) { "a" * 2049 }

it "truncates the alert" do
expect(notification.packaged_message.size.to_i).to eq(APN::Notification::DATA_MAX_BYTES)
Expand All @@ -117,13 +117,13 @@
end

it "has payload truncated only the alert" do
expect(notification.packaged_message).to eq({aps:{alert: "a" * 235 }}.to_json)
expect(notification.packaged_message).to eq({aps:{alert: "a" * 2027 }}.to_json)
end
end

context "when payload is a hash" do
let(:payload) do
{ alert: { 'loc-args' => ["a" * 300] }}
{ alert: { 'loc-args' => ["a" * 2049] }}
end

it "truncates the alert" do
Expand All @@ -136,7 +136,7 @@
end

context "when payload is multibyte string" do
let(:payload) { "»" * 256 }
let(:payload) { "»" * 2048 }

it "truncates the alert in a way that no multibyte character gets truncated " do
expect(notification.payload_size).to eq(APN::Notification::DATA_MAX_BYTES - 1)
Expand Down

0 comments on commit 339b3af

Please sign in to comment.