Giter Club home page Giter Club logo

Comments (19)

Raikerian avatar Raikerian commented on July 17, 2024

Hi,

can you provide us more information on how to reproduce this crash?

from qmchatviewcontroller-ios.

yakubbaev avatar yakubbaev commented on July 17, 2024

@tranngoclinh88
Deleting if clause in ChatViewController.swift's updateMessages method did the trick.

    func updateMessages() {
        // Retrieving messages - comment out if clause here
//        if (self.storedMessages()?.count > 0 && self.totalMessagesCount == 0) {
//            self.insertMessagesToTheBottomAnimated(self.storedMessages()!)
//            self.loadMessages()
//        } else {
            if self.totalMessagesCount == 0 { SVProgressHUD.showWithStatus("SA_STR_LOADING_MESSAGES".localized, maskType: SVProgressHUDMaskType.Clear) }
            ServicesManager.instance().chatService.messagesMemoryStorage.messagesWithDialogID(self.dialog?.ID)
            ServicesManager.instance().cachedMessagesWithDialogID(self.dialog?.ID, block: {
                [unowned self] (collection: [AnyObject]!) -> Void in
                if (collection.count > 0) {
                    self.insertMessagesToTheBottomAnimated(collection as! [QBChatMessage])
                }
                self.loadMessages()
            })
//        }
    }

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

@yakubbaev you have an outdated sample-chat swift code, please update. This was fixed already with new method from QMChatViewController:

func updateMessages() {

        // Retrieving messages
        if (self.storedMessages()?.count > 0 && self.totalMessagesCount == 0) {
            self.updateDataSourceWithMessages(self.storedMessages()!)
            self.loadMessages()
        } else {
            if self.totalMessagesCount == 0 { SVProgressHUD.showWithStatus("SA_STR_LOADING_MESSAGES".localized, maskType: SVProgressHUDMaskType.Clear) }

            ServicesManager.instance().cachedMessagesWithDialogID(self.dialog?.ID, block: {
                [unowned self] (collection: [AnyObject]!) -> Void in
                if (collection.count > 0) {
                    self.insertMessagesToTheBottomAnimated(collection as! [QBChatMessage])
                }
                self.loadMessages()
            })
        }
    }

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

@tranngoclinh88 if you still have a problem please give us more information on how to reproduce the crash.

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

Same for me.
In my debugging, I saw it happen in here self.collectionView performBatchUpdates:

- (void)insertMessagesToTheBottomAnimated:(NSArray *)messages {
    NSAssert([NSThread isMainThread], @"You are trying to insert messages in background thread!");
    NSAssert([messages count] > 0, @"Array must contain messages!");

    if (self.chatSections == nil) {
        NSDictionary *sectionsAndItems = [self updateDataSourceWithMessages:messages];
        NSArray *sectionsToInsert = sectionsAndItems[kQMSectionsInsertKey];
        NSArray *itemsToInsert = sectionsAndItems[kQMItemsInsertKey];

        NSIndexSet *sectionsIndexSet = [self indexSetForSectionsToInsert:sectionsToInsert];

        __weak __typeof(self)weakSelf = self;
        [self.collectionView performBatchUpdates:^{
            //
            __typeof(weakSelf)strongSelf = weakSelf;
            if ([sectionsIndexSet count] > 0) [strongSelf.collectionView insertSections:sectionsIndexSet];
            [strongSelf.collectionView insertItemsAtIndexPaths:itemsToInsert];

        } completion:nil];
        return;
    }

    NSUInteger sectionsToInsert = 0;
    NSMutableArray *indexPathToInsert = [NSMutableArray array];

    for (QBChatMessage *message in messages) {
        NSAssert(message.dateSent != nil, @"Message must have dateSent!");

        if ([self indexPathForMessage:message] != nil) continue;

        QMChatSection *firstSection = [self.chatSections firstObject];

        NSUInteger sectionIndex = [self.chatSections indexOfObject:firstSection];

        if ([message.dateSent timeIntervalSinceDate:[firstSection firstMessageDate]] > self.timeIntervalBetweenSections || firstSection == nil) {

            // move previous sections
            NSArray *indexPathToInsert_t = [indexPathToInsert copy];
            for (NSIndexPath *indexPath in indexPathToInsert_t) {
                NSIndexPath *updatedIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section + 1];
                [indexPathToInsert replaceObjectAtIndex:[indexPathToInsert indexOfObject:indexPath] withObject:updatedIndexPath];
            }

            QMChatSection* newSection = [QMChatSection chatSectionWithMessage:message];
            [self.chatSections insertObject:newSection atIndex:0];

            sectionIndex = [self.chatSections indexOfObject:newSection];
            sectionsToInsert++;
        } else {
            [firstSection.messages insertObject:message atIndex:0];
        }

        [indexPathToInsert addObject:[NSIndexPath indexPathForRow:0
                                                        inSection:sectionIndex]];
    }

    NSMutableIndexSet *sectionsIndexSet = [NSMutableIndexSet indexSet];
    for (NSUInteger i = 0; i < sectionsToInsert; i++) {
        [sectionsIndexSet addIndex:i];
    }

    __weak __typeof(self)weakSelf = self;
    [self.collectionView performBatchUpdates:^{
        //
        __typeof(weakSelf)strongSelf = weakSelf;
        if ([sectionsIndexSet count] > 0) [strongSelf.collectionView insertSections:sectionsIndexSet];
        [strongSelf.collectionView insertItemsAtIndexPaths:indexPathToInsert];
    } completion:^(BOOL finished) {
        //
        __typeof(weakSelf)strongSelf = weakSelf;
        [strongSelf scrollToBottomAnimated:NO];
    }];
}
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the collection view after the update (5) must be equal to the number of sections contained in the collection view before the update (2), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).'
*** First throw call stack:
(0x257462eb 0x24f12dff 0x257461c1 0x25f1cd3b 0x2a0c0f5d 0x2a0c3fb7 0x2a0c3e45 0x29ac8471 0x94bd65 0x94abf7 0x1db681 0x2574acc4 0x256752ad 0x25678d47 0xe539b3 0x257495b1 0x25678c88 0x9a1953 0xe555bd 0xe28a23 0x2574acc4 0x256752ad 0x25678d47 0xebc2e3 0x2917cbf 0x2917cab 0x291c771 0x25708fc5 0x257074bf 0x25659bb9 0x256599ad 0x268d3af9 0x29945fb5 0x41fbd1 0x2530c873)
libc++abi.dylib: terminating with uncaught exception of type NSException

screen shot 2016-01-22 at 5 13 23 pm

Firstly, I got self.chatSections.count = 2. And then I didn't know why chatSections.count = 5.

Please let me know how to fix this. Thanks!

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

@buithuyen
What version of QMChatViewController are you using?

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

This is pod that I used:

Using QMChatViewController (0.3.3)
Using QMServices (0.3.4)
Using QuickBlox (2.6.3)
Using Quickblox-WebRTC (2.1.1)

I realize that it will happen when I present other view (Ex: Select photos from photo browser).
I guess that something has been released

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

Are you unsubscribing from chat delegates when presenting any other controller?
You can receive crash due to attempt of performing animation while there is no such controller on screen.

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

@Raikerian I have removed QMChatServiceDelegate in viewWillDisappear like this:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self checkChatConnection];

    [[IAWChatManager sharedInstance] addDelegate:self];
    [[QMApi instance].chatService addDelegate:self];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];

    [[IAWChatManager sharedInstance] removeDelegate:self];
    [[QMApi instance].chatService removeDelegate:self];

    [[NSNotificationCenter defaultCenter] removeObserver:self.observerDidBecomeActive];
    [[NSNotificationCenter defaultCenter] removeObserver:self.observerDidEnterBackground];

    // Deletes typing blocks.
    [self.dialog clearTypingStatusBlocks];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"StopPlayingAudioInChat" object:nil];
}

But I'm still getting crash when I send message from other controller.
Do you have any suggestion to fix this?

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

What do you mean by 'sending message from other controller'?

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

Oh, I present other controller to get location and photos and comeback chat controller to send message.
Every time I do that app will cash.

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

Add Exception for all Exceptions, and try to reproduce crash again. You should see which line in your chat controller causes that crash. Attach that line/method here.

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024
*** Assertion failure in -[QMChatCollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:], /SourceCache/UIKit_Sim/UIKit-3347.44.2/UICollectionView.m:4056
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the collection view after the update (5) must be equal to the number of sections contained in the collection view before the update (0), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).'

Don't have any exception
Crashing in QMChatViewController.m method insertMessagesToTheBottomAnimated: line 321

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

Where are you calling this method in your chat controller?

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

I just implement this code:

__typeof__(self) strongSelf = weakSelf;

NSArray* images = result;

QBChatMessage* message = [QBChatMessage new];
message.contentType = IAWMessageContentTypeImage;
message.senderID = strongSelf.senderID;
message.dialogID = strongSelf.dialog.ID;
message.dateSent = [NSDate date];
message.deliveredIDs = @[@(self.senderID)];
message.readIDs = @[@(self.senderID)];
message.text = [[images firstObject] JSONString];

[[QMApi instance].chatService sendMessage:message
                                 toDialog:strongSelf.dialog
                            saveToHistory:YES
                            saveToStorage:YES
                               completion:^(NSError* _Nullable error) {
    DLogWarn();
}];

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

Can you please provide any sample with this crash being reproducible?

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

Okey, I will send you later. Thanks!

from qmchatviewcontroller-ios.

buithuyen avatar buithuyen commented on July 17, 2024

I followed this issue quickblox-ios-sdk/issues/273
This has helped me fix this problem. Thanks so much!

from qmchatviewcontroller-ios.

Raikerian avatar Raikerian commented on July 17, 2024

Nice to hear that you fixed it, check out our latest samples :)

from qmchatviewcontroller-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.