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

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

在此消息中,发送工作正常,在接收消息中,它在警报视图中显示,与在代码中一样。收到消息时,此方法正在调用,位于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];
    }
}
}


我想在另一个类的对话视图(在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;
}


因此,我的问题是如何将接收到的消息以数组或字典的形式接收,并带到tablepath单元格中indexpath的行中,以在tableview中显示。

最佳答案

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

我在Swift Wrapper周围做了一个XMPPFramework,它对JSQMessageViewController使用UI

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

您可以检出here

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

10-12 00:11
查看更多