2

I'm trying to export an UIImage as a sticker for Messages app, but I can't find any documentation about this.

I have my project with the Sticker Pack extension enabled and see that Xcode created a new Stickers.xcassets, every image that I add there manually appears on Messages app to use as a sticker, but how can I save an image programatically there, so the user can create stickers from any image ?

All I can find is information related to creating stickers without doing any code, just shipping an app with predefined images.

let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "Test")

I know how create a MSSticker from the image file, but after this I don't know how to proceed and make this newly created sticker appear on Messages app.

herd
  • 155
  • 2
  • 19

1 Answers1

1

Stickers are loaded from stickers assets catalog .xcstickers. This catalog is a resource file/folder, that means this is placed inside your bundle. All files inside your bundle are not writable and they have only read permissions. IMO what you need to do is:

  • You have to store your users custom images in any one of the sandboxed folders (Documents, Library and temp).

  • Read image from this folder and create MSSticker from it same way as you did. - let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "Test") and add. this sticker to array.

  • In your MSStickerBrowserViewController you will load stickers from array created in previous step.

Like this

override func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {
    stickers.count
}

override func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView,
                                 stickerAt index: Int) -> MSSticker {
    stickers[index]
}
Denis Kakačka
  • 697
  • 1
  • 8
  • 21
  • Ok, this shows a browser view with the stickers that I created. But I don't understand how showing this view can import them to the Messages app. This is an example of what I want to do: https://imgur.com/jLkuyo5 – herd Jun 09 '20 at 20:46
  • Did you solve this ? Sorry but I can't think of way how to make it work like you wish. – Denis Kakačka Jun 14 '20 at 08:32