MSStickerView shows wrong sticker as a preview

Summary of bug I've just reported (27751901):

I create animated stickers dynamically, store them in cache subdirectories as *.png and use MSStickerView to present them to the user. MSStickerView displays always only first generated APNG (per app install), so if I add 10 MSStickerView and assign different stickers to them, they all will display the same sticker. Further functionality of MSStickerView works perfectly fine though, so when user taps or drag&drops it - it becomes correct sticker, as expected. Also sending it to recipient works fine.


Steps to Reproduce:

1. Create png with animation frames programatically

2. Save it in sandbox

3. Create and add MSStickerView to view hierarchy

4. Create MSSticker with url of last created file in sandbox

5. Repeat 1-4 but creating different animation in 1-st step


Expected Results: See 2 different animation previews

Actual Results: See the same animation duplicated on both MSStickerViews (this, which was created first)


Version: iOS 10 beta 4 (14A5322e) + Xcode 8.0 beta 4 (8S188o)


Notes:

It happens only with animated PNG files.

It looks like MSStickerView is having some internal cache for preview which is not correctly refreshed when sticker property is set.


Actual question:

Maybe somebody met this problem as well? Some workarounds?

Accepted Reply

I've addressed this problem:


iOS is somehow caching once loaded sticker preview and remembers it by filename.

In example described above, where this problem appears I've been using different subfolders in cache directory, but PNG files themself used to have the same name "sticker.png".

Workaround to this problem is easy then: use different names for dynamically generated stickers, because iOS recognises them by name and full URL matters only when you start dragging sticker to actually use it.

Replies

I've addressed this problem:


iOS is somehow caching once loaded sticker preview and remembers it by filename.

In example described above, where this problem appears I've been using different subfolders in cache directory, but PNG files themself used to have the same name "sticker.png".

Workaround to this problem is easy then: use different names for dynamically generated stickers, because iOS recognises them by name and full URL matters only when you start dragging sticker to actually use it.

iOS 以某种方式缓存一次加载不干胶标签预览和记得它的文件名。 在上文所述的示例中,这个问题出现在哪里我一直在使用缓存目录,但是 PNG 文件本身曾经有相同的名字"sticker.png"中的不同子文件夹。 这一问题的解决方法是容易然后︰ 使用不同的名称,用于动态生成的贴纸,因为 iOS 认出他们的名称和完整 URL 事项,只有当你开始拖动贴纸要真正使用它。

mmm odd. I am seeing this behavior too, but all files have unique filenames. Also, curiously, in a set of 216 images, this only happens in files that are saved by the message extension itself - files that have been saved by the host app work fine.

Again, only the preview is wrong. As soon as I drag and drop a sticker, it shows the correct image. My files have an UDID based name, and they are saved in the app container shared area.

Same here, I'm guessing there are some caching issues to work out.

hi


i have same issue using just the sticker app. It should be showing a different colored mouse in each column, some show correctly others dont...each has a unique name


I'm having the same issue

  • I have a messages app that loads stickers via the stickerBrowserView
  • Example code: if let url = Bundle.main.url(forResource: ("\(index)"), withExtension: "png", subdirectory: "Stickers") {...
  • I have to change the name of the sticker in order to update the preview in the browser view
  • For example, 1, 2, 3 become 1a, 2a, 3a
  • However it appears that the previews persist if I do this a few times, 1a ...1b...1c..., and then go back to 1a
  • I've tried force cleaning the build directory, removing and reinstalling, etc, but nothing works
  • It looks like the only solution is to change the updated file names with every update which is super annoying

Isn't there a way to clear the cache programatically? Why do these preview files persist?

I wonder if it has anything to do with the Recents sticker/app pane that first appears when you open the app try from messages? It keeps a record of all the stickers you used. I bet this is why they're persistent.

Thanks for posting your observations. Your solution worked for me, too. I am concerned about accumulating APNGs everytime the user adds to or changes one of these stickers, seeing as they seem to be retained in some fashion. Only way to clear them out seems to be to delete the messages app. I've not found any documentation on this. Have you heard anything via the bug report?