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:
And it shows as:
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:
Thanks!
You should - as @larme comments - be able to use UNNotificationAttachmentOptionsThumbnailClippingRectKey. However, there seems to be a bug there somewhere:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With