XMPPFramework - 如果尚未创建vCard,则不会更新昵称

时间:2013-09-19 10:33:59

标签: ios xmpp xmppframework

新用户向XMPP注册时出现问题。我无法在vCard上设置昵称,但是如果用户的vCard已经存在,那么同样的代码就能正常工作。

dispatch_queue_t queue = dispatch_queue_create("queue", DISPATCH_QUEUE_PRIORITY_DEFAULT);
dispatch_async(queue, ^{

    XMPPvCardCoreDataStorage *xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
    XMPPvCardTempModule *xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
    [xmppvCardTempModule  activate:[self xmppStream]];

    XMPPvCardTemp *myVcardTemp = [xmppvCardTempModule myvCardTemp];

    if (myVcardTemp == nil) {
       // I am stuck here, unable to create empty VCard for new User
    }
    else {
        [myVcardTemp setNickname:@"iphone"];
        [xmppvCardTempModule updateMyvCardTemp:myVcardTemp];
    }

});

在xmpp中第一次创建vcard的任何线索?

2 个答案:

答案 0 :(得分:6)

XMPPvCardTemp *myvCardTemp = [xmppvCardTempModule myvCardTemp];
if (!myvCardTemp) 
{
    NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
    XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
    [newvCardTemp setNickname:@"nick"];
    [xmppvCardTempModule updateMyvCardTemp:newvCardTemp];
}
else
{
    //Set Values as normal
}

答案 1 :(得分:0)

我使用了下面的代码,但似乎它不是创建卡片,它总是进入if块,如果我遗漏任何东西,你能不能请它。

     XMPPvCardTemp *myvCardTemp = [xmppvCardTempModule myvCardTemp];
    [xmppvCardTempModule  activate:[self xmppStream]];
if (!myvCardTemp)
{
    NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
    XMPPvCardTemp *newvCardTemp =[XMPPvCardTemp vCardTempFromElement:vCardXML];

    [newvCardTemp setNickname:@"exist"];
    [xmppvCardTempModule updateMyvCardTemp:newvCardTemp];
    NSLog(@"no");
}
else
{
    NSLog(@"yes");

    //Set Values as normal
    [myvCardTemp setNickname:@"new"];
    [xmppvCardTempModule updateMyvCardTemp:myvCardTemp];

}