Ios -[XBMessage messageHash]:发送到实例的选择器无法识别
我集成了Cocoapods中的以下库,您可以在 该库用于在Xcode项目中集成XMPP聊天。 我还从自述文件中添加了建议的代码。我把它贴在下面供你参考 AppDelegate.mIos -[XBMessage messageHash]:发送到实例的选择器无法识别,ios,objective-c,iphone,xmpp,jsqmessagesviewcontroller,Ios,Objective C,Iphone,Xmpp,Jsqmessagesviewcontroller,我集成了Cocoapods中的以下库,您可以在 该库用于在Xcode项目中集成XMPP聊天。 我还从自述文件中添加了建议的代码。我把它贴在下面供你参考 AppDelegate.m [[XBChatModule sharedInstance] setUsername:@"admin"]; [[XBChatModule sharedInstance] setPassword:@"admin"]; [[XBChatModule sharedInstance] setHost:@
[[XBChatModule sharedInstance] setUsername:@"admin"];
[[XBChatModule sharedInstance] setPassword:@"admin"];
[[XBChatModule sharedInstance] setHost:@"sflashcard.com"];
[[XBChatModule sharedInstance] connect];
[[XBChatModule sharedInstance] setAvatarFormat:@"http://dev.sflashcard.com/images/mantis_logo.png?test=%@"];
[[XBChatModule sharedInstance] setAvatarPlaceHolder:[UIImage imageNamed:@"girl_9"]];
- (void)viewDidLoad
{
self.jidStr = @"binh.nx@sflashcard.com";
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:@"XBChatModuleNewAvatar" object:nil];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)reloadData
{
[self.collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
视图控制器继承自XBMessageViewController
ViewController.m
[[XBChatModule sharedInstance] setUsername:@"admin"];
[[XBChatModule sharedInstance] setPassword:@"admin"];
[[XBChatModule sharedInstance] setHost:@"sflashcard.com"];
[[XBChatModule sharedInstance] connect];
[[XBChatModule sharedInstance] setAvatarFormat:@"http://dev.sflashcard.com/images/mantis_logo.png?test=%@"];
[[XBChatModule sharedInstance] setAvatarPlaceHolder:[UIImage imageNamed:@"girl_9"]];
- (void)viewDidLoad
{
self.jidStr = @"binh.nx@sflashcard.com";
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated
{
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadData) name:@"XBChatModuleNewAvatar" object:nil];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)reloadData
{
[self.collectionView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
在我发送消息之前,代码工作正常。每当我按下发送按钮,它就会在控制台中抛出以下错误,从而使应用程序崩溃
2015-09-01 17:20:41.742 Test[16064:251944] -[XBMessage messageHash]: unrecognized selector sent to instance 0x7ffc91cc4180
2015-09-01 17:20:41.800 Test[16064:251944] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[XBMessage messageHash]: unrecognized selector sent to instance 0x7ffc91cc4180'
*** First throw call stack:
(
0 CoreFoundation 0x000000011260aa75 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001122a3bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000112611d1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001125697ef ___forwarding___ + 495
4 CoreFoundation 0x0000000112569578 _CF_forwarding_prep_0 + 120
5 Test 0x000000010ebaf7ed -[JSQMessagesCollectionViewFlowLayout messageBubbleSizeForItemAtIndexPath:] + 301
6 Test 0x000000010ebb02a7 -[JSQMessagesCollectionViewFlowLayout sizeForItemAtIndexPath:] + 71
7 Test 0x000000010ebc5c93 -[JSQMessagesViewController collectionView:layout:sizeForItemAtIndexPath:] + 131
8 UIKit 0x00000001116369be -[UICollectionViewFlowLayout _getSizingInfos] + 988
9 UIKit 0x0000000111637839 -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 526
10 UIKit 0x00000001116332b7 -[UICollectionViewFlowLayout collectionViewContentSize] + 66
11 Test 0x000000010ebc2d85 -[JSQMessagesViewController scrollToBottomAnimated:] + 325
12 Test 0x000000010ebc2c34 -[JSQMessagesViewController finishReceivingMessageAnimated:] + 388
13 Test 0x000000010ebc2aa0 -[JSQMessagesViewController finishReceivingMessage] + 48
14 Test 0x000000010ebfaac3 -[XBMessageViewController loadDataToTable] + 1507
15 Test 0x000000010ebf9be9 -[XBMessageViewController viewDidLoad] + 73
16 Test 0x000000010ead0760 -[ViewController viewDidLoad] + 96
17 UIKit 0x0000000111104580 -[UIViewController loadViewIfRequired] + 738
18 UIKit 0x000000011110477e -[UIViewController view] + 27
19 UIKit 0x0000000111023509 -[UIWindow addRootViewControllerViewIfPossible] + 58
20 UIKit 0x00000001110238a1 -[UIWindow _setHidden:forced:] + 247
21 UIKit 0x000000011102ff8c -[UIWindow makeKeyAndVisible] + 42
22 UIKit 0x0000000110fda0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
23 UIKit 0x0000000110fdce3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
24 UIKit 0x0000000110fdbd35 -[UIApplication workspaceDidEndTransaction:] + 179
25 FrontBoardServices 0x0000000115aab243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
26 CoreFoundation 0x000000011253fc7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
27 CoreFoundation 0x00000001125359c5 __CFRunLoopDoBlocks + 341
28 CoreFoundation 0x0000000112535183 __CFRunLoopRun + 851
29 CoreFoundation 0x0000000112534bc6 CFRunLoopRunSpecific + 470
30 UIKit 0x0000000110fdb7a2 -[UIApplication _run] + 413
31 UIKit 0x0000000110fde580 UIApplicationMain + 1282
32 Test 0x000000010ead06d3 main + 115
33 libdyld.dylib 0x0000000112b3c145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
我知道它说,我没有在类
XBMessage
中实现函数messageHash
,但是在我从中下载的示例代码中,同样的代码可以很好地工作。请帮助我解决此错误。XBChatModule所基于的库已经更新。如果查看XBMessage
符合的协议的历史记录:您可以看到自从写入XBChatModule
以来,方法messageHash
是必需的
因此,我建议联系
XBChatModule
的开发人员,让他们更新自己的代码,或者,实现自己的messageHash
方法。谢谢@michaelrccurtis,事实上我不知道messageHash中应该包含什么,尽管我阅读了该方法声明中的文档。你能给我推荐这样一个教程的链接,详细说明“messageHash”函数应该包含什么吗?我建议首先使用NSObjecthash
属性,即在messageHash
中使用just havereturn self.hash
,因为这是现在JSQ库中实现的默认行为。您可能需要注意这里的问题:它列出了您可能希望使用不同实现的原因,但这取决于您的特定设置。谢谢,该错误不会重复,但现在出现了一个新错误,它表示“无效参数不满足:messageSenderId!=nil”,错误在Pods/JSQMessageViewController/JSQMessageViewController/Controllers/JSQMessageViewController中。m:452这意味着未在MessageViewController
或消息本身中设置senderId
,具体取决于错误发生的位置。我建议将此作为一个新问题,尽管我怀疑问题再次在于XBChatModule尚未更新。Ok@Michaercurtis。谢谢你的帮助。我正在努力解决我自己,否则我会张贴它明天。