gpt4 book ai didi

ios - 如何在xmpp的tableview中显示收到的消息

转载 作者:行者123 更新时间:2023-11-29 01:38:28 26 4
gpt4 key购买 nike

我正在使用 xmpp 框架制作一个聊天应用程序。

我已经通过引用此链接在我的项目中设置了 XMPPFramework:- http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190

在此消息中,发送工作正常,在接收消息中,它显示在警报 View 中,就像在代码中一样。当收到消息时,此方法正在调用,它位于 Appdelegate.m 文件中:-

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{ DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD);
// A simple example of inbound message handling.

if ([message isChatMessageWithBody])
{
XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[message from]
xmppStream:xmppStream
managedObjectContext:[self managedObjectContext_roster]];

NSString *body = [[message elementForName:@"body"] stringValue];
NSString *displayName = [user displayName];

if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:displayName
message:body
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];

}
else
{
// We are not active, so use a local notification instead
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = @"Ok";
localNotification.fireDate=[NSDate dateWithTimeIntervalSinceNow:1.0];
localNotification.alertBody = [NSString stringWithFormat:@"From: %@\n%@",displayName,body];
NSLog(@"localNotification.alertBody:-%@",localNotification.alertBody);
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
}
}

我想在另一个类的对话 View (在 TableView 中)中显示收到的消息。

这里是在tableview中显示发送消息的代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

UITableViewCell *cell=nil;
cell=[tableView dequeueReusableCellWithIdentifier:@"MessageCellIdentifier" forIndexPath:indexPath];

cell.textLabel.text=[[messages objectAtIndex:indexPath.row] objectForKey:@"msg"];
cell.detailTextLabel.text=@"You";
cell.textLabel.textAlignment=NSTextAlignmentRight;
return cell;
}

所以,我的问题是如何将接收到的消息放入数组或字典中,并将其放入索引路径中的行的 TableView 单元格中以显示在 TableView 中。

最佳答案

据我了解,您想显示两个人之间的聊天 View ?

我围绕 XMPPFramework 制作了一个 Swift Wrapper,它使用 JSQMessageViewController 作为 UI

它将简化基本聊天应用程序的开发。

可以看看here .

关于ios - 如何在xmpp的tableview中显示收到的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32709019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com