我已经集成了来自 Cocoapods 的以下库,您可以在https://github.com/EugeneNguyen/XBChatModule找到代码及其示例代码
pod 'XBChatModule'
该库用于在 Xcode 项目中集成 XMPP Chat。我还从它的自述文件中添加了建议的代码。供您参考,我将其粘贴在下面
AppDelegate.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"]];
视图控制器继承自XBMessageViewController
视图控制器.m
- (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
我理解它说,我没有messageHash
在 Class 中实现该函数,但相同的代码在我从GithubXBMessage
下载的示例代码中运行良好。请帮我解决这个错误。