1

I'm trying to make a very simple stickers iMessage application with user being proposed to in-app purchase when they click on some of the stickers.

I have a custom view controller that implements UIViewController, UICollectionViewDelegate, UICollectionViewDataSource (source: https://github.com/jelenakrmar/customStickerApp).

I am now trying to override the default behaviour when the user taps or peels the sticker.

My first attempt was at the level of the collectionView

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
// open the in-app purchase window
}

but it doesn't work

Maybe I would need to extend MSStickerView and do something in 'didTap' and 'didLongPress'.

Does anyone have some experience with overriding the behaviour of iMessage when selecting a sticker?

Amal T S
  • 3,327
  • 2
  • 24
  • 57
tencnivel
  • 183
  • 1
  • 10

2 Answers2

3

I'm in a similar situation and have a UICollectionController loading stickers via a MSStickerView in my UICollectionViewCell.

I subclassed a UICollectionViewCell and placed a MSStickerView onto the cell contentView. After this, I disabled touch by:

(stickerView)?.isUserInteractionEnabled = false

The collectionViewController function didSelectItemAt now works.

0

It seems like, if your UICollectionViewCell has a MSStickerView (or possibly imports Messages framework), the didSelectItemAt delegate doesn't get called.

For example, if I wanted to have a Sticker Extension with free and locked stickers, I would create two different cells in my UICollectionView. One has a MSStickerView and the second one only has an UIImageView. If a free sticker is tapped, iOS handles everything with the UICollectionView delegate not being fired. However, if a user taps a locked sticker, the delegate will fire, and can be handled by the didSelectItemAt delegate.

I haven't found any documentation that points to this yet.

htdahms
  • 104
  • 1
  • 7
  • yes, I came to the same conclusion: you need 2 different kinds of cells one with MSStickerView the other with something else (eg UIImageView). The problem is that you can't animate a apng in a UIImageView. I tried to use a third party library for this but it ruined the performance and the app got rejected. I ended up using an UIImageView, this is not ideal of course (user cannot see the animated stickers running before buying them). I mark your answer as true. – tencnivel Oct 02 '17 at 02:33