This record I use XMPP implementation of the upload avatar process, found that XMPP really very powerful many features have been implemented. We just have to call it straight. Here's the code.
Introduction Header File This header file needs to be imported by itself or the method under Xmppvcardtemp cannot be called.
#import "XMPPvCardTemp.h"
Declaring related objects
Declaration Upload avatar related objects @property (nonatomic, strong) Xmppvcardcoredatastorage *xmppvcardstorage; @property (nonatomic, Strong) Xmppvcardtempmodule *xmppvcardtempmodule; @property (nonatomic, strong) Xmppvcardavatarmodule *xmppvCardAvatarModule ;
Initializing related objects
Initialization method-(void) setupstream{ _xmppstream = [[Xmppstream alloc] init]; [_xmppstream adddelegate:self Delegatequeue:dispatch_get_main_queue ()]; _xmpprosterdatastorage = [[Xmpprostercoredatastorage alloc] init]; _xmpproster = [[Xmpproster alloc] initwithrosterstorage:_xmpprosterdatastorage];// _xmpproster.autofetchroster = yes;// _xmpproster.autoacceptknownpresencesubscriptionrequests = yes;// _xmppvcardstorage = [ Xmppvcardcoredatastorage Sharedinstance]; _xmppvcardtempmodule = [[Xmppvcardtempmodule alloc] initwithvcardstorage:_xmppvcardstorage]; _xmppvcardavatarmodule = [[Xmppvcardavatarmodule alloc] initwithvcardtempmodule:_xmppvcardtempmodule]; [_xmppvcardtempmodule adddelegate:self Delegatequeue:dispatch_get_main_queue ()]; [_xmppvcardavatarmodule adddelegate:self Delegatequeue:dispatch_get_main_queue ()]; }
In the callback with the successful loginXmppstream object to associate
Login Success-(void) Xmppstreamdidauthenticate: (Xmppstream *) sender{ [self goonline]; NSLog (@ "landing success"); [[Nsuserdefaults Standarduserdefaults] setobject:@ "Success" forkey:xmpplogin]; [_xmpproster Activate:_xmppstream]; [_xmpproster adddelegate:self Delegatequeue:dispatch_get_main_queue ()]; [_xmppvcardtempmodule Activate:_xmppstream]; [_xmppvcardavatarmodule Activate:_xmppstream]; [Self queryroster]; }
Upload your avatar's code
-(void) offeringprofile{nsxmlelement *vcardxml = [nsxmlelement elementwithname:@ "VCard" stringvalue:@ "vcard-temp"]; Nsxmlelement *photoxml = [nsxmlelement elementwithname:@ "PHOTO"]; Nsxmlelement *typexml = [nsxmlelement elementwithname:@ "TYPE" stringvalue:@ "Image/jpeg"]; UIImage *image = [UIImage imagewithdata:[nsdata datawithcontentsoffile:[[nsbundle Mainbundle] pathforresource:@ " Changmen "oftype:@" jpg "]]; NSData *datafromimage = uiimagejpegrepresentation (image, 0.7f); Nsxmlelement *binvalxml = [nsxmlelement elementwithname:@ "Binval" Stringvalue:[datafromimage base64Encoding]]; [Photoxml Addchild:typexml]; [Photoxml Addchild:binvalxml]; [Photoxml Addchild:photoxml]; Xmppvcardtemp * myvcardtemp = [_xmppvcardtempmodule myvcardtemp]; NSLog (@ "%@", myvcardtemp); if (myvcardtemp) {myvcardtemp.photo = Datafromimage; [_xmppvcardtempmodule updatemyvcardtemp:myvcardtemp]; }else {xmppvcardtemp *NEWVCArdtemp = [Xmppvcardtemp vcardtempfromelement:vcardxml]; Newvcardtemp.nickname = @ "Nick"; [_xmppvcardtempmodule updatemyvcardtemp:newvcardtemp]; } }
Original address: http://blog.csdn.net/qqmcy/article/details/42422893
XMPP Client Development-----User upload Avatar (iv)