5

当新用户注册 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 的任何线索?

4

2 回答 2

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
}
于 2013-10-08T14:05:17.327 回答
0

我使用了以下代码,但似乎它没有创建卡片,它总是进入 if block,如果我遗漏了什么,请你看看它。

     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];

}
于 2014-01-24T05:44:20.573 回答