How to block the selection of a sticker in iMessage

348 views Asked by At

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?

2

There are 2 answers

1
htdahms On BEST ANSWER

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.

0
Jan-Michael Tressler On

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.