当我在应用中收到XMPP Presence时,我会将其内容添加到NSMutableDictionary
以将其发送到另一个ViewController
。如果我使用NSLog
来查看此词典的内容,我可以看到一切正常。但是当我从另一个NSMutableDictionary
访问此ViewController
时,我找不到JID.Rest的东西存储得很好。
这是我在存储XMPP Presence内容时所做的事情,即JID和名称。
- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence
{
NSString *fromUser = [[presence from]user]; //name of user
NSString *fromUserJID = [NSString stringWithFormat:@"%@",[presence from]] ;
NSLog(@"presence from user JID :- %@", fromUserJID); // This shows the JID.
[_locationDictionary setObject:fromUser forKey:@"fromUser"];
[_locationDictionary setObject:fromUserJID forKey:@"fromJID"];
NSLog(@"locationary dictionary :- %@",_locationDictionary ); // This shows name as well as JID.
// add to array
[_presenceArray addObject:_locationDictionary];
现在,当我尝试在另一个ViewController中访问它时,我这样做: -
NSString *str=view.annotation.title; //This has the name of the user.
NSLog(@"annotation title :- %@", str);
for (NSDictionary *obj in appDelegate.presenceArray)
{
NSString *titleString = [obj objectForKey:@"fromUser"];
if ([str isEqualToString:titleString]) //for the same username I need the JID
{
NSString *jidString = [obj objectForKey:@"fromJID"];
[ dict setObject:jidString forKey:@"jid"]; //dict is NSMutableDictionary
NSLog(@"retrieved jid is :- %@", dict); // THIS IS NULL
答案 0 :(得分:2)
[presence from]将提供NSObject类型的XMPPJid。
XMPPJID *jid = [presence from];
尝试以这种方式获取Jid字符串
NSString *fromUserJID = [[presence from] full];//Will give Jid have user, resource, domain
//OR
NSString *fromUserJID = [presence fromStr]; //Only give Jid of user.