2014-01-28 71 views
2

我使用以下代碼無法創建電子名片。它總是在if區塊中。有人可以看看它,看看我是否失去了什麼?XMPPFramework - 創建電子名片

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

我試過這個,但它仍然沒有工作...被調用來獲得vcard的函數總是返回nil。

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

該函數返回零值。有什麼我失蹤?其他

一件事是,它發送一個錯誤日誌:

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

+0

嘿,你有沒有找到解決辦法? – esh

回答

1

最後,這是我做電子名片編輯

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


} 

希望它可以幫助你的方式...... 。