Reputation: 3219
i am making a chat app with xmpp framework.
I have setup XMPPFramework in my project by referring this link:- http://code.tutsplus.com/tutorials/building-a-jabber-client-for-ios-xmpp-setup--mobile-7190
In this message sending is working perfectly and in receive message it is show in alertview as it is in code. When message received this method is calling which is in Appdelegate.m file:-
- (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];
}
}
}
And i want to show that received messages in conversation view (in tableview) which is in an other class.
Here the code which is displaying send messages in 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;
}
So, my question is how to take that received messages in array or in dictionary and take that to tableview cell for row at indexpath to show in tableview.
Upvotes: 0
Views: 664