[flutter_local_notifications] Allow notification actions on ios to work with remote (non-local) notifications #2681
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Changes
Why
Currently, to show notifications you need to send a data only message so that flutter_local_notifications can show the message, which will allow the action button to work correctly. (including a notification in the notification message when sending, as well as a category, will cause flutter_firebase_messaging to show it automatically but actions don't work). However, data only messages on iOS are not completely reliable and are sometimes delayed or never get received.
So it makes sense to allow actions to function correctly when a notification message that contains a notification and a category is received and automatically shown by flutter_firebase_messaging.
Notes
Since the payload is set to
response.notification.request.content.userInforather thanresponse.notification.request.content.userInfo['PAYLOAD'](since the PAYLOAD key won't exist if it's not a local notification), this will include other keys which weren't sent in notification.data like theapsblock, and other keys such asgcm.message_id,google.c.a.e,google.c.fid,google.c.sender.idetc.In order for these to not appear in the payload of the response object (
NotificationResponse) returned by the methodgetNotificationAppLaunchDetailsand used in the functions given foronDidReceiveNotificationResponseandonDidReceiveBackgroundNotificationResponsethey have been filtered out by looking at what the firebase messaging filters out in it's method remoteMessageUserInfoToDict method.Another thing is that
FirebaseMessaging.onMessageOpenedApp.listencan't be used on iOS (but should still be used for android) because it's effectively replaced byonDidReceiveNotificationResponseinflutterLocalNotificationsPlugin.initialize().