当我在应用程序中收到 XMPP Presence 时,我将其内容添加到 NSMutableDictionary
以将其发送到另一个 ViewController
。如果我使用 NSLog
来查看这本字典的内容,我可以看到一切都很好。但是当我从另一个 ViewController
访问这个 NSMutableDictionary
时,我找不到 JID。其余的东西存放得很好。
这就是我在存储 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
最佳答案
[presence from] will give XMPPJid which is NSObject type.
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.
关于ios - 无法从 NSMutableDictionary iOS 应用程序检索 XMPP JID。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20298088/