我正在制作基于聊天的应用程序我能够发送消息但无法在聊天屏幕中收到消息,所以任何人都可以帮助我 这是我的代码
if ([[message elementForName:@"body"] stringValue]==nil) {
}
else
{
NSString *messageBody = [[message elementForName:@"body"] stringValue];
XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[message from]
xmppStream:xmppStream
managedObjectContext:[self managedObjectContext_roster]];
NSString *displayName = [user displayName];
BOOL isComposing = NO;
NSString *MyString;
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// [dateFormatter setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
[dateFormatter setDateFormat:@"HH:mm,yyyy/MM/dd"];
MyString = [dateFormatter stringFromDate:now];
NSLog(@"TIME AND DATE=>%@",MyString);
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
NSString *myJID=[NSString stringWithFormat:@"%@@xxxx-mac-mini-2.local",[defaults valueForKey:@"userNameJID"]];
NSString *friendID=[[[message attributeForName:@"from"] stringValue] stringByDeletingLastPathComponent];
NSLog(@"---chatToUserId=>%@",friendID);
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];
NSString *msg = [[message elementForName:@"body"] stringValue];
NSString *from = [[message attributeForName:@"from"] stringValue];
// [xmppMessageArchivingStorage archiveMessage:message outgoing:NO xmppStream:xmppStream];
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:msg forKey:@"msg"];
[m setObject:from forKey:@"sender"];}
在xmpp委托方法中是didReceiveMessage但是如何分配给聊天屏幕类。
答案 0 :(得分:0)
你需要学习:
F1 195d;speed;Avg
Date/time
Date/time F1 195d;speed;Avg
2014-11-19 00:00:00 7.9694
是与XMPPMessageArchiving
捆绑在一起的示例模块,它将所有传入和传出的消息存储到CoreData支持的数据库。XMPPFramework
- Apple提供的标准类,用于向NSFetchedResultsController
或UITableView
提供数据,您可以将其用作“聊天屏幕”类的核心,它会自动跟踪新消息和更新用户界面。示例UICollectionView
项目有一个由UITableView和NSFRC支持的“名册屏幕”示例,“聊天屏幕”的唯一两个区别是:
iPhoneXMPP
个实体XMPPMessageArchiving_Message_CoreDataObject
仅提取与单个“聊天”相关的消息,例如NSPredicate
并将好友的JID传递给此谓词