Skip to content

Commit

Permalink
Merge pull request #106 from Sai/add-ios15-payload
Browse files Browse the repository at this point in the history
Add target-content-id & interruption-level & relevance-score to payload
  • Loading branch information
benubois authored Sep 7, 2021
2 parents 09fe3e9 + 567fffe commit 2e49648
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 20 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ These are all Accessor attributes.
| `category` | "
| `custom_payload` | "
| `thread_id` | "
| `target_content_id` | "
| `interruption_level` | Refer to [Payload Key Reference](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363) for details. iOS 15+
| `relevance_score` | Refer to [Payload Key Reference](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363) for details. iOS 15+
| `apns_id` | Refer to [Communicating with APNs](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html) for details.
| `expiration` | "
| `priority` | "
Expand Down
6 changes: 5 additions & 1 deletion lib/apnotic/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module Apnotic

class Notification < AbstractNotification
attr_accessor :alert, :badge, :sound, :content_available, :category, :custom_payload, :url_args, :mutable_content, :thread_id

attr_accessor :target_content_id, :interruption_level, :relevance_score

def background_notification?
aps.count == 1 && aps.key?('content-available') && aps['content-available'] == 1
end
Expand All @@ -21,6 +22,9 @@ def aps
result.merge!('url-args' => url_args) if url_args
result.merge!('mutable-content' => mutable_content) if mutable_content
result.merge!('thread-id' => thread_id) if thread_id
result.merge!('target-content-id' => target_content_id) if target_content_id
result.merge!('interruption-level' => interruption_level) if interruption_level
result.merge!('relevance-score' => relevance_score) if relevance_score
end
end

Expand Down
50 changes: 31 additions & 19 deletions spec/apnotic/notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

subject { notification }

# <https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html>
# <https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363>
describe "remote notification payload" do

before do
notification.alert = "Something for you!"
notification.badge = 22
notification.sound = "sound.wav"
notification.content_available = false
notification.category = "action_one"
notification.thread_id = 'action_id'
notification.custom_payload = { acme1: "bar" }
notification.alert = "Something for you!"
notification.badge = 22
notification.sound = "sound.wav"
notification.content_available = false
notification.category = "action_one"
notification.thread_id = "action_id"
notification.target_content_id = "target_content_id"
notification.interruption_level = "passive"
notification.relevance_score = 0.8
notification.custom_payload = { acme1: "bar" }
end

it { is_expected.to have_attributes(token: "token") }
Expand All @@ -27,6 +30,9 @@
it { is_expected.to have_attributes(content_available: false) }
it { is_expected.to have_attributes(category: "action_one") }
it { is_expected.to have_attributes(thread_id: "action_id") }
it { is_expected.to have_attributes(target_content_id: "target_content_id") }
it { is_expected.to have_attributes(interruption_level: "passive") }
it { is_expected.to have_attributes(relevance_score: 0.8) }
it { is_expected.to have_attributes(custom_payload: { acme1: "bar" }) }
end

Expand Down Expand Up @@ -91,14 +97,17 @@
context "when everything is specified" do

before do
notification.alert = "Something for you!"
notification.badge = 22
notification.sound = "sound.wav"
notification.content_available = 1
notification.category = "action_one"
notification.thread_id = 'action_id'
notification.custom_payload = { acme1: "bar" }
notification.mutable_content = 1
notification.alert = "Something for you!"
notification.badge = 22
notification.sound = "sound.wav"
notification.content_available = 1
notification.category = "action_one"
notification.thread_id = 'action_id'
notification.target_content_id = "target_content_id"
notification.interruption_level = "passive"
notification.relevance_score = 0.8
notification.custom_payload = { acme1: "bar" }
notification.mutable_content = 1
end

it { is_expected.to eq (
Expand All @@ -108,9 +117,12 @@
badge: 22,
sound: "sound.wav",
category: "action_one",
'content-available' => 1,
'mutable-content' => 1,
'thread-id' => 'action_id'
'content-available' => 1,
'mutable-content' => 1,
'thread-id' => 'action_id',
'target-content-id' => 'target_content_id',
'interruption-level' => 'passive',
'relevance-score' => 0.8
},
acme1: "bar"
}.to_json
Expand Down

0 comments on commit 2e49648

Please sign in to comment.