XMPPFramework - Create vCard

对着背影说爱祢 提交于 2019-12-24 06:06:15

问题


I used following code to no avail in creating a vCard. It always goes in if block. Can someone please look into it to see if I am missing anything?

xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
XMPPvCardTemp *myvCardTemp = [xmppvCardTempModule myvCardTemp];

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

[myvCardTemp setNickname:@"someNick"];
[myvCardTemp setMiddleName:@"somegender"];
[xmppvCardTempModule updateMyvCardTemp:myvCardTemp];

I have tried this but its still not working... The function which is called to get the vcard returns the nil always.

- (XMPPvCardTemp *)vCardTempForJID:(XMPPJID *)jid shouldFetch:(BOOL)shouldFetch

This function returns the nil value. Is there anything I am missing?

One other thing is that it sends an error to the log:

Error saving - Error Domain=NSCocoaErrorDomain Code=1570 "The operation couldn’t be completed. (Cocoa error 1570.)


回答1:


Finally this is the way i have done vcard edit

 -(void)Editvcard
 {
NSMutableDictionary *getdic = [[NSMutableDictionary alloc] init];
getdic = [[NSUserDefaults standardUserDefaults] valueForKey:@"UservCard"];

NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
//  myvCardTemp = newvCardTemp;
//}
[newvCardTemp setGivenName:[getdic valueForKey:@"username"]];
[newvCardTemp setSortString:[getdic valueForKey:@"status"]];
[newvCardTemp setJid:[XMPPJID jidWithString:[[NSUserDefaults standardUserDefaults] stringForKey:@"kXMPPmyJID"]]];
[newvCardTemp setFormattedName:[getdic valueForKey:@"username"]];
[newvCardTemp setEmailIDnew:[getdic valueForKey:@"emailid"]];    


NSString *img_name = [DatabaseAccess documentsPathForFileName:[getdic valueForKey:@"userimage"]];
NSData *pngData = [NSData dataWithContentsOfFile:img_name];

NSString *strThumb = @"";
if([[[UIDevice currentDevice] systemVersion] floatValue] >=7)
{
    //Encode Image Data
    strThumb = [Base64 encode:pngData];
    //strMapThumb = [pngData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
}
else
{
    //Encode Image Data
    strThumb = [Base64 encode:pngData];
}

[newvCardTemp setPhoto:strThumb];
[xmppvCardTempModule updateMyvCardTemp:newvCardTemp];


}

hope it helps you....



来源:https://stackoverflow.com/questions/21397543/xmppframework-create-vcard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!