0

Cocoapods から次のライブラリを統合しました。コードとそのサンプル コードはhttps://github.com/EugeneNguyen/XBChatModuleにあります。

pod 'XBChatModule'

このライブラリは、Xcode プロジェクトで XMPP チャットを統合するために使用されます。ReadMe ファイルから提案されたコードも追加しました。参考までに下に貼っておきます

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

ViewController.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

messageHashClassに関数を実装していないということは理解していますが、 GithubXBMessageからダウンロードしたサンプル コードでは同じコードが正常に動作します。このエラーを解決するのを手伝ってください。

4

1 に答える 1

2

XBChatModuleに基づいているライブラリはその後更新されました。https://github.com/jessesquires/JSQMessagesViewController/commits/develop/JSQMessagesViewController/Model/JSQMessageData.hXBMessageに準拠するプロトコルの履歴を見ると、メソッドが作成されてから必須になっていることがわかります。 .messageHashXBChatModule

そのため、開発者に連絡しXBChatModuleてコードを更新してもらうか、独自のmessageHashメソッドを実装することをお勧めします。

于 2015-09-01T12:21:47.027 に答える