1

I’m using the new UserNotifications framework to include image attachments in the notifications for my iOS app. I’m pulling images from different databases such as from Facebook as well as my from my own Firebase database.

I have a couple of issues.

First, if a notification image is displayed from my firebase database and the height is larger than the width and also the height exceeds the maximum image height for the notification (I’m not sure specifically what this is), the image is compressed vertically and the aspect ratio is incorrect. Note that the same images are presented correctly within my application.

Second, if a notification image is displayed from Facebook’s database and the height is larger than the width and also the height exceeds the maximum image height for the notification, the entire image will be resized to fit the maximum allowable height for the notification image, leaving white vertical bars on either side.

I would like to ensure that images that I am storing to firebase are never presented with a skewed aspect ratio. And for images that exceed the maximum allowable height, I would like to crop these images to avoid the white bars on either side.

Also worth noting, for images that I am storing to firebase, I get the same behaviour whether a photo is taken with my application or taken in the native iOS camera app and uploaded at a later time, which leads to believe that the issue is in relation to how the images are being stored to firebase as opposed to how the images are being captured and whether or not they include the appropriate metadata.

The Firebase related code I’m using to store images is simply:

if let uploadData = UIImageJPEGRepresentation(imageToStore, 0.1) {

        imageStorageRef.put(uploadData, metadata: nil, completion: { (metadata, error) in

…
Copernicus
  • 90
  • 5

1 Answers1

1

A few thoughts:

  • I'd curl -v both URLs and compare headers, maybe there's an obvious solution in that the Facebook image has some header that you need to add to the images you store in Firebase Storage.
  • Facebook may also be resizing the image on the fly (requesting an image of the appropriate height/width) using technology similar to Imgix/Cloudinary. You can integrate one of these providers relatively easily.
  • You might need to build some extra logic into your notification thumbnail code to either resize the image (NSHipster post) or crop the image to an appropriate thumbnail size (docs).
Community
  • 1
  • 1
Mike McDonald
  • 15,609
  • 2
  • 46
  • 49