title: Local Notification Attachments Disappearing In Notification Center?
body: <p>I'm having trouble figuring out why my Notification attachments are not available once a notification goes to the Notification Center (device lock screen, or swipe-down from top on home screen). </p>
  
  <p>The notifications are being successfully delivered, with the images displayed as thumbnails in the banner view, and on the expanded or long-look notification where the default 'manage' &amp; 'view' buttons are. If the user taps the notification while the notification is in drop-down banner mode, the notification opens the specified view controller in the app and the image is grabbed from the notification and displayed in the view controller.</p>
  
  <p>However, if the notification is viewed after it goes to the notification center (that is viewed from the lock screen or swipe-down from the top of the home screen and selected from either of the default 'open' or 'view' buttons) the image is not passed to the specified view controller. The other notification content is, but not the image.</p>
  
  <p>In my <code>func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void)</code> function located in my AppDelegate I have the following code:</p>
  
  <pre><code>print("ATTACHMENT IS: \(String(describing: response.notification.request.content.attachments.first))")
  
  // GRAB 1ST NOTIFICATION ATTACHMENT AND CONVERT TO UIMAGE AND SET IN MESSAGECONTENT VC
                      if let attachment = response.notification.request.content.attachments.first {
                          if attachment.url.startAccessingSecurityScopedResource() {
                              if let data = NSData(contentsOfFile: attachment.url.path) as Data? {
                                  messageContentVC.messagePicture = UIImage(data: data)
                                  print("MESSAGEPICTURE VAR IS SET TO: \(String(describing: messageContentVC.messagePicture))")
                                  attachment.url.stopAccessingSecurityScopedResource()
                              }
  
                              /* THIS WORKS FINE W/ BANNER DROP DOWN BUT NOT NOTIFCENTER
                              if let imageData = NSData(contentsOf: attachment.url) {
                                  let image = UIImage(data: imageData as Data)
  
                                  messageContentVC.messagePicture = image
                                  print("MESSAGEPICTURE VAR IS SET TO: \(String(describing: messageContentVC.messagePicture))")
                                  attachment.url.stopAccessingSecurityScopedResource()
                              }*/
                              else {
                                  print("SOMETHING WENT WRONG IN APPDELEGATE TRYING TO PUSH MESSAGEPICTURE.")
                                  print(" ")
                                  print(" ")
                              } // END ELSE
                          } // END ATTACHMENT.URL
                      } // END ATTACHMENT = RESPONSE
  </code></pre>
  
  <p>I've tried both contentsOfFile and contentsOf in the commented out section with the same result: the notification image is only passed to the view controller if the user touches the initial drop-down banner notification. </p>
  
  <p>The preceding "ATTACHMENT IS:" statement shows the optional image as being there just prior to the rest of the code shown above. Whenever it gets to the rest of the code it ends up in the "else" statement.</p>
  
  <p>Any insight or guidance anyone can offer is much appreciated.</p>