- I'm creating a custom stickerpack using an iMessages application
- I have 28 stickers in the pack, all apng, all < 500kb
- Sticker were created in photoshop, exported as image sequences, compressed using imageOptim, compiled into APNG using PNG Animator (os x)
- I put my stickers in a Stickers folder within MessagesExtension but the problem still occurs when images are within the MessagesExtension as well
- I can run the app, build is fine, but after a few moments I get the following errors:
- The problem is intermittent—happens when I start dragging a sticker, if I expand/collapse the browser, if I send stickers as attachment—seems random
- I thought it was my PNG files so I replaced them with GIFS, same problem
I replaced the images with static PNG and it works fine
- I also have a separate app that uses an embedded viewController as recommended by Apple, the same behavior occurs
- I've tested the app on a 7+, 6, both with iOS 10.2
- Here is my code:
import Messages
import UIKit
class MessagesViewController: MSMessagesAppViewController, MSStickerBrowserViewDataSource {
var stickers = [MSSticker]()
var numStickers = 28
override func viewDidLoad() {
super.viewDidLoad()
loadStickers()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func willBecomeActive(with conversation: MSConversation) {
super.willBecomeActive(with: conversation)
presentViewController(with: presentationStyle)
}
private func presentViewController(with presentationStyle:
MSMessagesAppPresentationStyle) {
for child in childViewControllers {
child.willMove(toParentViewController: nil)
child.view.removeFromSuperview()
child.removeFromParentViewController()
}
let controller = MSStickerBrowserViewController(stickerSize: .small)
addChildViewController(controller)
controller.view.frame = view.bounds
controller.view.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(controller.view)
controller.view.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
controller.view.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
controller.view.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
controller.view.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
controller.didMove(toParentViewController: self)
controller.stickerBrowserView.dataSource = self
}
func loadStickers() {
for index in 1...numStickers{
if let url = Bundle.main.url(forResource: ("\(index)"), withExtension: "png", subdirectory: "Stickers") {
print(url)
do {
let sticker = try MSSticker(contentsOfFileURL: url, localizedDescription: "")
stickers.append(sticker)
} catch {
print(error)
}
}
}
}
func numberOfStickers(in stickerBrowserView: MSStickerBrowserView) -> Int {
return stickers.count
}
func stickerBrowserView(_ stickerBrowserView: MSStickerBrowserView, stickerAt index: Int) -> MSSticker {
return stickers[index]
}
}