XMPPFramework: Trying to update nickname on VCard

2019-09-17 04:39发布

问题:

This question is as simple as its title says: I'm trying to update a user nickname on his VCard but I cannot. I'm using this code:

dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
    dispatch_async(queue, ^{
        XMPPvCardTemp *myVcardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
        [myVcardTemp setNickname:@"a_nickname"];
        [[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:myVcardTemp];
    });

I cannot imagine why this piece of code don't want to work while the same piece, but updating photo, is working like a charm:

NSData *imageData = UIImagePNGRepresentation(anImage);
        dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
        dispatch_async(queue, ^{
            XMPPvCardTemp *myVcardTemp = [[[self appDelegate] xmppvCardTempModule] myvCardTemp];
            [myVcardTemp setPhoto:imageData];
            [[[self appDelegate] xmppvCardTempModule] updateMyvCardTemp:myVcardTemp];
        });

Any help would be appreciated... this is driving me crazy

NOTES: I'm using OpenFire as XMPP server

And this is the stanza the server returns me when I'm trying to update the nickname

RECV: <iq xmlns="jabber:client" type="result" from="7db55e68-cb18-4826-befd-0eb9269637aa@000.000.000.000" to="7db55e68-cb18-4826-befd-0eb9269637aa@000.000.000.000/2cfc4f88"><chat_jorges xmlns="vcard-temp"><NICKNAME>chat_jorges</NICKNAME></chat_jorges></iq>

(I changed my server's ip for 000.000.000.000)

回答1:

EDIT : I WAS TOTALLY WRONG DON'T READ THIS

Actually when I read the source code of XMPP, I wonder how it could set a value. In XMPPvCardTempBase.h :

#define XMPP_VCARD_SET_STRING_CHILD(Value, Name) NSXMLElement *elem = [self elementForName:(Name)];
//it looks like a get and not a set??

And in XMPPvCardTemp.m :

- (void)setNickname:(NSString *)nick {
    XMPP_VCARD_SET_STRING_CHILD(nick, @"NICKNAME");
}

Maybe there is something as KVC somewhere... Can you try this in the source code:

 - (void)setNickname:(NSString *)nick {
       XMPP_VCARD_SET_STRING_CHILD(nick, @"NICKNAME") = nick ;
   }