Skip to content

Commit

Permalink
Merge pull request #329 from Nattfodd/apns2_non_header_fields_fix
Browse files Browse the repository at this point in the history
Apns2 - content-available field missing fix
  • Loading branch information
amaierhofer committed Jan 17, 2017
2 parents 3d9fd89 + e147ad4 commit 5a44348
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
14 changes: 1 addition & 13 deletions lib/rpush/daemon/apns2/delivery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,7 @@ def build_request(notification)
end

def prepare_body(notification)
aps = {}

primary_fields = [:alert, :badge, :sound, :category,
'content-available', 'url-args']
primary_fields.each do |primary_field|
field_value = notification.send(primary_field.to_s.underscore.to_sym)
next unless field_value

aps[primary_field] = field_value
end

hash = { aps: aps }
hash.merge!(notification_data(notification).except(HTTP2_HEADERS_KEY) || {})
hash = notification.as_json.except(HTTP2_HEADERS_KEY)
JSON.dump(hash).force_encoding(Encoding::BINARY)
end

Expand Down
7 changes: 4 additions & 3 deletions spec/functional/apns2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def create_notification
notification.alert = 'test'
notification.device_token = fake_device_token
notification.data = notification_data
notification.content_available = 1
notification.save!
notification
end
Expand All @@ -63,7 +64,7 @@ def create_notification
.with(
:post,
"/3/device/#{fake_device_token}",
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\"}}",
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\",\"content-available\":1}}",
headers: {} }
)
.and_return(fake_http2_request)
Expand Down Expand Up @@ -91,8 +92,8 @@ def create_notification
.with(
:post,
"/3/device/#{fake_device_token}",
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\"},"\
"\"some_field\":\"some value\"}",
{ body: "{\"aps\":{\"alert\":\"test\",\"sound\":\"default\","\
"\"content-available\":1},\"some_field\":\"some value\"}",
headers: { 'apns-topic' => bundle_id }
}
).and_return(fake_http2_request)
Expand Down

0 comments on commit 5a44348

Please sign in to comment.