Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media-attachment crops image in ios 10 notification

iOS10 notifications allow us to add images as media-attachments to them. Unfortunately, I haven't found any good way to control attachment's appearance inside the notification.

For example, I'm adding as attachment this image: enter image description here

And it shows as:

enter image description here

I'm passing square-images and want to avoid image-crop (as you can see one ear of cat has been cut).

I'm sending notifcation (as a local one) via this snippet:

    let content = UNMutableNotificationContent()
    content.title = "Test notification"
    content.body = "Test notification"
    content.categoryIdentifier = "myNotificationCategory"

    let attachement = try! UNNotificationAttachment(identifier: "image",
                                                                url: Bundle.main.url(forResource: "cat", withExtension: "png")!,
                                                                options: nil)

    content.attachments = [ attachement ]
    let request = UNNotificationRequest(identifier:requestIdentifier, content: content, trigger: nil)
    UNUserNotificationCenter.current().delegate = self
    UNUserNotificationCenter.current().add(request){(error) in
        if (error != nil){
        }
    }

So the questions are:

  • Can I avoid image crop? (If not - how to remove image at all?)
  • Bonus question: is there a way to show 2 media-attachments in one notification (while it's collapsed)

Thanks!

like image 988
Konstantin Loginov Avatar asked Oct 19 '22 03:10

Konstantin Loginov


1 Answers

You should - as @larme comments - be able to use UNNotificationAttachmentOptionsThumbnailClippingRectKey. However, there seems to be a bug there somewhere:

  • https://openradar.appspot.com/27708976?
  • https://forums.developer.apple.com/message/154320#154320
like image 106
Roy Solberg Avatar answered Oct 20 '22 16:10

Roy Solberg