@@ -394,10 +394,13 @@ class ApsAlert(object):
394394 action_loc_key: Key of the text in the app's string resources to use to localize the
395395 action button text (optional).
396396 launch_image: Image for the notification action (optional).
397+ custom_data: A dict of custom key-value pairs to be included in the ApsAlert dictionary
398+ (optional)
397399 """
398400
399401 def __init__ (self , title = None , subtitle = None , body = None , loc_key = None , loc_args = None ,
400- title_loc_key = None , title_loc_args = None , action_loc_key = None , launch_image = None ):
402+ title_loc_key = None , title_loc_args = None , action_loc_key = None , launch_image = None ,
403+ custom_data = None ):
401404 self .title = title
402405 self .subtitle = subtitle
403406 self .body = body
@@ -407,6 +410,7 @@ def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=
407410 self .title_loc_args = title_loc_args
408411 self .action_loc_key = action_loc_key
409412 self .launch_image = launch_image
413+ self .custom_data = custom_data
410414
411415
412416class APNSFcmOptions (object ):
@@ -835,6 +839,14 @@ def encode_aps_alert(cls, alert):
835839 if result .get ('title-loc-args' ) and not result .get ('title-loc-key' ):
836840 raise ValueError (
837841 'ApsAlert.title_loc_key is required when specifying title_loc_args.' )
842+ if alert .custom_data is not None :
843+ if not isinstance (alert .custom_data , dict ):
844+ raise ValueError ('ApsAlert.custom_data must be a dict.' )
845+ for key , val in alert .custom_data .items ():
846+ _Validators .check_string ('ApsAlert.custom_data key' , key )
847+ # allow specifying key override because Apple could update API so that key
848+ # could have unexpected value type
849+ result [key ] = val
838850 return cls .remove_null_values (result )
839851
840852 @classmethod
0 commit comments