Invalid parameter not satisfying: messageSenderId

2019-08-29 05:29发布

I integrated 'XBChatModule' Library from Cocoapods into my project.

When I run the code for the first time, It crashed the app by throwing following error -[XBMessage messageHash]: unrecognized selector sent to instance and it got resolved by changing XBMessage.m file as below

XBMessage.m

- (NSUInteger)messageHash
{
    return self.hash;
}

But this produces new issue saying

Assertion failure in -[ChatMessagesController collectionView:cellForItemAtIndexPath:], /Users/Neelacharya/Harshit/LIve Projects/Project/V1/Source/Project/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.m:452

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: messageSenderId != nil'

*** First throw call stack:
(
    0   CoreFoundation                      0x000000011161ca75 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001112b1bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000011161c8da +[NSException raise:format:arguments:] + 106
    3   Foundation                          0x000000010edcfb6f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
    4   CinchGaming                         0x000000010d7be3c5 -[JSQMessagesViewController collectionView:cellForItemAtIndexPath:] + 693
    5   CinchGaming                         0x000000010d7f5f6d -[XBMessageViewController collectionView:cellForItemAtIndexPath:] + 141
    6   UIKit                               0x00000001102b9fab -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 244
    7   UIKit                               0x00000001102bb6e4 -[UICollectionView _updateVisibleCellsNow:] + 3445
    8   UIKit                               0x00000001102bf391 -[UICollectionView layoutSubviews] + 243
    9   UIKit                               0x000000010fd041c3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
    10  QuartzCore                          0x000000010f9d2c58 -[CALayer layoutSublayers] + 150
    11  QuartzCore                          0x000000010f9c787e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    12  QuartzCore                          0x000000010f9c76ee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    13  QuartzCore                          0x000000010f93536e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
    14  QuartzCore                          0x000000010f936482 _ZN2CA11Transaction6commitEv + 390
    15  QuartzCore                          0x000000010f936aed _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
    16  CoreFoundation                      0x0000000111551507 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    17  CoreFoundation                      0x0000000111551460 __CFRunLoopDoObservers + 368
    18  CoreFoundation                      0x0000000111547293 __CFRunLoopRun + 1123
    19  CoreFoundation                      0x0000000111546bc6 CFRunLoopRunSpecific + 470
    20  GraphicsServices                    0x0000000112796a58 GSEventRunModal + 161
    21  UIKit                               0x000000010fc8a580 UIApplicationMain + 1282
    22  CinchGaming                         0x000000010d67e463 main + 115
    23  libdyld.dylib                       0x0000000111b4e145 start + 1
    24  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I understand the reason of crash is the member messageSenderId is nil at 452'th line of JSQMessagesViewController.m file. But I don't know why does it occur and how to get it resolved.

I also reported as issue to the authors at Github, but couldn't get response.

I would appreciate if you can help me to solve the problem.

2条回答
一纸荒年 Trace。
2楼-- · 2019-08-29 06:19

It think the application is crashing on this line:

NSString *messageSenderId = [messageItem senderId];
NSParameterAssert(messageSenderId != nil);

When I dig into that I found that the senderIdis being set from XBMessageViewController's loadDataToTable method. The only reason I can find the value for senderId is nil is you aren't setting the values for jidStr and senderId.

You will require to set jidStr and senderId and XBMessageViewController, where jidStr is receiver and senderId is self user.

Hope this helps.

查看更多
做自己的国王
3楼-- · 2019-08-29 06:27

You need to register your class like [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];

查看更多
登录 后发表回答