Skip to content

Commit ecfc125

Browse files
committed
Pass custom APNs sounds through for FCM notifications
apns_config only ever set aps['sound'] when the notification's sound attribute was exactly 'default', so any custom sound value configured by the user was silently omitted from the APNs payload sent via FCM. Pass the sound through when set, and keep omitting the key entirely when no sound is configured (so notifications stay silent, matching the existing behavior of android_notification and the plain APNs client). Fixes #715
1 parent a5ea408 commit ecfc125

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎lib/rpush/client/active_model/fcm/notification.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def apns_config
7676
aps = ActiveSupport::OrderedHash.new
7777
aps['mutable-content'] = 1 if mutable_content
7878
aps['content-available'] = 1 if content_available
79-
aps['sound'] = 'default' if sound == 'default'
79+
aps['sound'] = sound if sound
8080
aps['badge'] = badge if badge
8181

8282
json['payload']['aps'] = aps

‎spec/unit/client/shared/fcm/notification.rb‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@
8787
expect(notification.as_json['message']['apns']['payload']['aps']['badge']).to eq(3)
8888
end
8989

90+
it 'passes through a custom sound to the apns payload' do
91+
notification.sound = 'custom.aiff'
92+
expect(notification.as_json['message']['apns']['payload']['aps']['sound']).to eq('custom.aiff')
93+
end
94+
95+
it 'omits the apns sound when no sound is set' do
96+
notification.sound = nil
97+
expect(notification.as_json['message']['apns']['payload']['aps']).not_to have_key('sound')
98+
end
99+
90100
it 'excludes the notification payload if undefined' do
91101
expect(notification.as_json['message']).not_to have_key 'notification'
92102
end

0 commit comments

Comments
 (0)