Search code examples
iosobjective-ciphonequickblox

How can i implement stickers in to quickblox iOS code


I am integrating Stickers to my chatviewcontroller .

But am not able to understand how can i take it forward , There is some code snippet provided on Quickblox documentation but confused where to place the code and how to handle stickers .enter code here

https://quickblox.com/developers/SimpleSample-chat_users-ios#Stickers

1 . pod "StickerPipe" - Done
2 . [STKStickersManager initWitApiKey:@"API_KEY"]; - Done
3. if ([STKStickersManager isStickerMessage:message]) {
[self.stickerImageView stk_setStickerWithMessage:message placeholder:nil placeholderColor:nil progress:nil completion:nil];
}

Is this the code i need to write for Input textview on chat . And how

@property (strong, nonatomic) STKStickerController *stickerController;
self.inputTextView.inputView = self.stickerController.stickersView;
[self reloadStickersInputViews];

Wrote the property , but not sure how to handle the sticker

5 .

- (void)stickerController:(STKStickerController *)stickerController didSelectStickerWithMessage:(NSString *)message {

//Send sticker message
}

What would be the code inside the delegate .

Please suggest .


Solution

  • We can add sticker by following steps, I have added for outgoing similarly we can add for incoming also

    i)Create a cell called QMChatStickerOutGoingCell and has imageView property say stickerImageView

    ii)ChatViewController (Subclass of QMChatViewController)need to know cell type for QMChatStickerOutGoingCell so we can execute like below

    - (Class)viewClassForItem:(QBChatMessage *)item {
    if ([STKStickersManager isStickerMessage: item.text]) {
            return [QMChatStickerOutGoingCell class];
        }
    //Add condition for other cells
    
    }
    

    iii)Update the sticker

    - (void)collectionView:(QMChatCollectionView *)collectionView 
    configureCell:(UICollectionViewCell *)cell forIndexPath:(NSIndexPath 
    *)indexPath{
    [super collectionView:collectionView configureCell:cell forIndexPath:indexPath];
    
    QMChatCell *chatCell = (QMChatCell *)cell;
    
    // subscribing to cell delegate
    [chatCell setDelegate:self];
    
    [chatCell containerView].highlightColor = [UIColor colorWithWhite:0.5 alpha:0.5];
    
    
    QBChatMessage *message = [self.chatDataSource messageForIndexPath:indexPath];
    
    if ([cell isKindOfClass:[QMChatStickerOutGoingCell class]]){
        [chatCell containerView].bgColor = [UIColor redColor];
        [(QMChatStickerOutGoingCell *)chatCell fillWithStickerMessage: message.text downloaded: [self.stickerController isStickerPackDownloaded: message.text]];
    }
    
    //Handle for other cells
    }