【问题标题】:(iOS) recursive vCard-temp request to the jabber server?(iOS) 对 jabber 服务器的递归 vCard-temp 请求?
【发布时间】:2012-01-10 07:45:11
【问题描述】:

我正在使用 xmpframework 创建一个 iphone 应用程序,一切正常,但我想使用以下代码更新我的个人资料图片。我收到了一些不正确的对服务器的递归 vCard-temp 请求。但图片已更新,并通知了我名单中的所有朋友。

//I clicked on the button
-(void)updatevCardButtonClicked{
   XMPPvCardTemp *vCardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
   NSLog(@"my vCardTemp: %@", vCardTemp);
   NSData *tempImage = [self getDataFromImage:[self resizeImage:userImage]];
   [vCardTemp setPhoto: tempImage];
   [[[self appDelegate] xmppvCardTempModule]updateMyvCardTemp:vCardTemp];
}

下面的输出和解释

my vCardTemp: *nil description*
MyApp[60625:6c1b] XMPPvCardCoreDataStorage: Triggering save (pendingRequests=0)
MyApp[60625:207] MyAppDelegate: xmppStream:didReceiveIQ: - E49C843A-5A05-4148-A4CF-B400062A83C0
MyApp[60625:207] MyAppDelegate: xmppStream:didReceivePresence: - <presence xmlns="jabber:client"    from="myJabberAccount@127.0.0.1/1948110991326183732515886" to="myJabberAccount@127.0.0.1/1948110991326183732515886">
  <status>At  work</status>
  <x xmlns="vcard-temp:x:update">
        <photo>1f6401ddea76826fddc4cd7ddc17741db6c9dabc</photo>
  </x>
  <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="></c>
  <x xmlns="vcard-temp:x:update">
        <photo>c3b2d65259a4fc1d37e56777697d4f5a9730fb03</photo></x><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="></c>
  </presence>
MyApp[60625:5323] XMPPRosterCoreDataStorage: handlePresence:xmppStream:

//repeat start from here, and the DidReceivePresence: will grow into tons of lines with the samthing
MyApp[60625:207] XMPPRosterCoreDataStorage: userForJID:xmppStream:managedObjectContext:
MyApp[60625:1e0b] XMPPRosterCoreDataStorage: userForJID:xmppStream:managedObjectContext:
MyApp[60625:207] XMPPRosterCoreDataStorage: resourceForJID:xmppStream:managedObjectContext:
MyApp[60625:5323] XMPPvCardCoreDataStorage: Triggering save (pendingRequests=0)
MyApp[60625:207] MyAppDelegate: xmppStream:didReceiveIQ: - (null)
MyApp[60625:1e0b] XMPPvCardCoreDataStorage: Triggering save (pendingRequests=0)
MyApp[60625:207] MyAppDelegate: xmppStream:didReceivePresence: - <presence xmlns="jabber:client" from="myJabberAccount@127.0.0.1/1948110991326183732515886" to="myJabberAccount@127.0.0.1/1948110991326183732515886">
 <status>At work</status>
 <x xmlns="vcard-temp:x:update">
     <photo>1f6401ddea76826fddc4cd7ddc17741db6c9dabc</photo>
 </x>
 <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="></c>
 <x xmlns="vcard-temp:x:update">
     <photo>c3b2d65259a4fc1d37e56777697d4f5a9730fb03</photo>
 </x>
 <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="></c>
 <x xmlns="vcard-temp:x:update">
     <photo>c3b2d65259a4fc1d37e56777697d4f5a9730fb03</photo>
 </x>
 <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4=">
 </c>
 </presence>

//repeat the above in the rest of the output with more and more "vcard-temp:x:update"

到目前为止我发现了什么,以下导致了这个问题,但我不知道在哪里可以解决它。

//i found that these two "SEND" cause the problem, the app just keep sending these two 
SEND: <iq type="get" to="myJabberAccount@127.0.0.1"><vCard xmlns="vcard-temp"/></iq>
SEND: <presence>
    <x xmlns="vcard-temp:x:update">
        <photo>1f6401ddea76826fddc4cd7ddc17741db6c9dabc</photo>
    </x>
    <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/>
    <x xmlns="vcard-temp:x:update">
        <photo>1f6401ddea76826fddc4cd7ddc17741db6c9dabc</photo>
    </x>
    <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/>
    <x xmlns="vcard-temp:x:update">
        <photo>f93ee3918c7baaf095edb9f6bede892c603161af</photo>
    </x>
    <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/>
    <x xmlns="vcard-temp:x:update">
        <photo>f93ee3918c7baaf095edb9f6bede892c603161af</photo>
    </x>
    <c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://code.google.com/p/xmppframework" ver="VyOFcFX6+YNmKssVXSBKGFP0BS4="/>
</presence>
 //this presence keep growing as you can see the repeated parts

【问题讨论】:

    标签: iphone vcf-vcard xmppframework


    【解决方案1】:

    我已经尝试解决这个问题很长一段时间了。让我知道这是否适合您。这是我的解释:

    每当您通过 xmppStream 发送出席信息时,它都会将其副本缓存在“myPresence”实例变量下。

    如果你在 XMPPStream.m 中寻找以下方法:

    - (void)continueSendElement:(NSXMLElement *)element withTag:(long)tag
    

    有一个关于 10-20 行的评论说:

    // Update myPresence if this is a normal presence element.
    // In other words, ignore presence subscription stuff, MUC room stuff, etc.
    

    当 XMPPvCardAvatarModule 类更新 vcard 时,它会引入诸如 (能力)标签之类的东西,这些标签会污染正常的存在元素。

    为了解决这个问题,我们需要清理那些不必要的标签。这是我编辑的代码的一部分:

    else if ([element isKindOfClass:[XMPPPresence class]])
    {
        // Update myPresence if this is a normal presence element.
        // In other words, ignore presence subscription stuff, MUC room stuff, etc.
    
        XMPPPresence *presence = (XMPPPresence *)element;
    
        // We use the built-in [presence type] which guarantees lowercase strings,
        // and will return @"available" if there was no set type (as available is implicit).
    
        NSString *type = [presence type];
        if ([type isEqualToString:@"available"] || [type isEqualToString:@"unavailable"])
        {
            NSArray *vCardXElem = [presence elementsForName:@"x"];
            NSArray *capabilitiesHash = [presence elementsForName:@"c"];
    
            for (NSXMLElement *x in vCardXElem)
            {
                [presence removeChildAtIndex:[x index]];
            }
    
            for (NSXMLElement *c in capabilitiesHash)
            {
                [presence removeChildAtIndex:[c index]];
            }
    
            if ([presence toStr] == nil && myPresence != presence)
            {
                myPresence = presence;
            }
        }
    
        [multicastDelegate xmppStream:self didSendPresence:(XMPPPresence *)element];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多