Skip to content

Commit 076ba7b

Browse files
Add live_activity_token to APNSConfig, allowing you to specify this token for APNS messages.
This change introduces: - Adding the `live_activity_token` field to the `APNSConfig` class - Updated unit test to verify that the `live_activity_token` is correctly included in the encoded message
1 parent 70013c8 commit 076ba7b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

firebase_admin/_messaging_encoder.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ def encode_apns(cls, apns):
530530
'payload': cls.encode_apns_payload(apns.payload),
531531
'fcm_options': cls.encode_apns_fcm_options(apns.fcm_options),
532532
}
533+
if apns.live_activity_token:
534+
result['live_activity_token'] = _Validators.check_string(
535+
'APNSConfig.live_activity_token', apns.live_activity_token, non_empty=True)
533536
return cls.remove_null_values(result)
534537

535538
@classmethod

firebase_admin/_messaging_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,17 @@ class APNSConfig:
334334
payload: A ``messaging.APNSPayload`` to be included in the message (optional).
335335
fcm_options: A ``messaging.APNSFCMOptions`` instance to be included in the message
336336
(optional).
337+
live_activity_token: An optional string that identifies the live activity to update.
337338
338339
.. _APNS Documentation: https://developer.apple.com/library/content/documentation\
339340
/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
340341
"""
341342

342-
def __init__(self, headers=None, payload=None, fcm_options=None):
343+
def __init__(self, headers=None, payload=None, fcm_options=None, live_activity_token=None):
343344
self.headers = headers
344345
self.payload = payload
345346
self.fcm_options = fcm_options
347+
self.live_activity_token = live_activity_token
346348

347349

348350
class APNSPayload:

tests/test_messaging.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,8 @@ def test_apns_config(self):
10941094
topic='topic',
10951095
apns=messaging.APNSConfig(
10961096
headers={'h1': 'v1', 'h2': 'v2'},
1097-
fcm_options=messaging.APNSFCMOptions('analytics_label_v1')
1097+
fcm_options=messaging.APNSFCMOptions('analytics_label_v1'),
1098+
live_activity_token='test_token_string'
10981099
),
10991100
)
11001101
expected = {
@@ -1107,6 +1108,7 @@ def test_apns_config(self):
11071108
'fcm_options': {
11081109
'analytics_label': 'analytics_label_v1',
11091110
},
1111+
'live_activity_token': 'test_token_string',
11101112
},
11111113
}
11121114
check_encoding(msg, expected)

0 commit comments

Comments
 (0)