filePath = [Imagesdatapath1 stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",imageName]];
 NSError *errror;
   NSData *pngData = UIImagePNGRepresentation(resizedImage);


 NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
 NSXMLElement *photoXML = [NSXMLElement elementWithName:@"PHOTO"];
 NSXMLElement *typeXML = [NSXMLElement elementWithName:@"TYPE" stringValue:@"image/jpg"];


  NSString *strEncoded = [Base64 encode:pngData];

  NSXMLElement *binvalXML = [NSXMLElement elementWithName:@"BINVAL" stringValue:strEncoded];

 [photoXML addChild:typeXML];
 [photoXML addChild:binvalXML];
 [vCardXML addChild:photoXML];

 XMPPvCardTemp *myvCardTemp = [XMPPvCardTempModule myvCardTemp];

 if (myvCardTemp) {
    [myvCardTemp setPhoto:pngData];
    [ XMPPvCardTempModule updateMyvCardTemp:myvCardTemp];
 }

     [pngData writeToFile:filePath atomically:YES];

 [[NSUserDefaults standardUserDefaults] setObject:Imagesdatapath1 forKey:@"primagepath"];
   [[NSUserDefaults standardUserDefaults] synchronize];

     [self uploadProfileImage:filePath];

请参阅上面的代码,我正在使用聊天应用程序。我不知道xmpp图片上传头像的概念。我想在xmpp服务器和本地数据库上上传个人资料图片(头像)。所以,我导入了像Base64XMPPvCardTempModule这样的库,但是直到它给出了很多库错误以及V卡怎么样。

最佳答案

1)首先,从Camera或Gallary中选择图像,然后将其调整为所需的格式:

NSData *img = [NSData dataWithData:UIImagePNGRepresentation(resizedImage)];

2)将您的XMPP值如下:
            NSXMLElement *vCardXML = [NSXMLElement elementWithName:@"vCard" xmlns:@"vcard-temp"];
            NSXMLElement *jidElement = [NSXMLElement elementWithName:@"JABBERID" objectValue:"your_jabberid_here"];
            NSXMLElement *profileUrlElement = [NSXMLElement elementWithName:@"PROFILEURL" stringValue:"server_file_path_of_image"];
            NSXMLElement *emailElement = [NSXMLElement elementWithName:@"EMAIL"];
            NSXMLElement *userIdElement = [NSXMLElement elementWithName:@"USERID" objectValue:"optional_if_you_want_set_email_id"];
            NSXMLElement *userNickname = [NSXMLElement elementWithName:@"NICKNAME" objectValue:"your_nickName_here"];

3)将每个NSXMLElement标签添加到vCard中,如下所示:
        [emailElement addChild:userIdElement];
        [emailElement addChild:[NSXMLElement elementWithName:@"INTERNET"]];
        [emailElement addChild:[NSXMLElement elementWithName:@"PREF"]];
        [vCardXML addChild:jidElement];
        [vCardXML addChild:emailElement];
        [vCardXML addChild:profileUrlElement];
        [vCardXML addChild:userNickname];

4)最后,如下更新您的vCard:
XMPPvCardTemp *newvCardTemp = [XMPPvCardTemp vCardTempFromElement:vCardXML];
            [newvCardTemp setPhoto:img];
            [self->xmppvCardTempModule updateMyvCardTemp:newvCardTemp];

您可以通过以下方式检查新设置的vcard照片:
 XMPPvCardCoreDataStorage *  xmppvCardStorage = [XMPPvCardCoreDataStorage sharedInstance];
  XMPPvCardTempModule * xmppvCardTempModule = [[XMPPvCardTempModule alloc] initWithvCardStorage:xmppvCardStorage];
    [xmppvCardTempModule  activate:[self xmppStream]];
   XMPPvCardTemp * vcard = [xmppvCardTempModule vCardTempForJID:[XMPPJID jidWithString:"your_jid_here" shouldFetch:YES];
    if (vcard.photo) {

        // YOUR_code_goes_here //
    }

关于ios - 如何在ios中的xmpp服务器上上传个人资料图片?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40815789/

10-13 04:07