tencnivel tencnivel - 3 years ago 191
iOS Question

How to block the selection of a sticker in iMessage

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

(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
and do something in '
' and '

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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download