ios - 无法从 NSMutableDictionary iOS 应用程序检索 XMPP JID。

标签 ios nsstring nsmutabledictionary xmppframework

当我在应用程序中收到 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/

相关文章:

ios - 是否可以将具有重复键的值添加到 NSDictionary?

ios - array.insert 不会保存元素

ios - 快速错误: "Type ' ( )' cannot conform to ' View'; only struct/enum/class types can conform to protocols"when calling function to write text

ios - 无法使用 Testflight 进行内部测试的 'Start Testing'

iOS 错误解析 JSON

ios - 更改嵌套 NSMutableDictionary 中的值

ios - 如何在类方法中实现键值对的简单本地缓存?

objective-c - SubstringWithRange NSString 内存泄漏

ios - UILabel、UIFont 和 UTF-8 三角形

iphone - iphonesdk附加字符串问题