XMPP Client Development-----User upload Avatar (iv)

Source: Internet
Author: User
Tags addchild vcard

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.