I would like to send a GIF Image from my iMessage extension. The message is sending with the image but the problem is that image is not animating.
My approach:
let msg = msgList[indexPath.row]
let message = MSMessage()
let msgLayout = MSMessageTemplateLayout()
if let title = msg.message { msgLayout.caption = title }
if let msgImg = msg.image { msgLayout.image = msgImg }
message.layout = msgLayout
if let conversation = self.activeConversation {
conversation.insert(message) { error in
print("Insert message error: \(String(describing: error))")
}
}
Also tried with mediaFileUrl
:
if let url = Bundle.main.url(forResource: "IMG_0673", withExtension: "gif") {
msgLayout.mediaFileURL = url
}
But when I tried with MSSticker
GIF is animating.
Code:
do {
let sticker = try MSSticker(contentsOfFileURL: Bundle.main.url(forResource:"AS001494_20", withExtension: "gif")!,localizedDescription: "a gif image")
if let conversation = self.activeConversation {
conversation.insert(sticker) { error in
print(error)
}
}
} catch {
print("Sticker error: \(error.localizedDescription)")
}
Is it possible to send animated GIF using MSMessage
and MSMessageTemplateLayout
?
You may need to use
insertAttachment(_:withAlternateFilename:completionHandler:)
and send the GIF as an attachment. I also could not get GIFs to animate withMSMessageTemplateLayout
. So you'll have something likeHappy coding