ios - Passing NSData to web service along with NSDictionary Parameter -


i have afnetworking services written in separate web service classe. upto have been doing fine passing nsdictionary parameters. got problem when need pass nsdata file web service.

here how im performing web service

 nsdata *imagedata = uiimagejpegrepresentation(self.profileimg.image, 0.5); // need pass imagedata      nsdateformatter *dateformatter=[[nsdateformatter alloc] init];     [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss"];      nsstring *stringfromdate = [dateformatter stringfromdate:[nsdate date]];      //encrypting password     nsstring *passwordstring = _password.text;     nsstring *passwordmd5 = [passwordstring md5string];      nsdictionary *params = @{@"username": _username.text,                              @"password": passwordmd5,                              @"email": _email.text,                              @"date":stringfromdate};      webservice *serviceobj = [[webservice alloc] init];     serviceobj.delegate = self;     [serviceobj performselectorinbackground:@selector(doregister:) withobject:params]; 

here how have written web service

nsmutabledictionary * parameters = [[nsmutabledictionary alloc]initwithdictionary:params];  nsurl *baseurl = [nsurl urlwithstring:@"http://www.example.com/register.php"];  afhttpsessionmanager * manager = [[afhttpsessionmanager alloc] initwithbaseurl:baseurl]; manager.responseserializer = [afjsonresponseserializer serializer];  [manager post:@"" parameters:parameters constructingbodywithblock:^(id<afmultipartformdata>  _nonnull formdata) {      [formdata appendpartwithfiledata:imagedata name:@"image" filename:@"profile.png" mimetype:@"image/png"];  } progress:nil success:^(nsurlsessiondatatask * _nonnull task, id  _nullable responseobject) {      [delegate didreceiveregisterresponse:responseobject];  } failure:^(nsurlsessiondatatask * _nullable task, nserror * _nonnull error) {  }]; 

but dont know how assign imagedata now.

i have done passing nsdata , nsdictionary inside array. below

[self performselectorinbackground:@selector(reloadpage:)                        withobject:[nsarray arraywithobjects:pageindex,firstcase,nil] ];   - (void) reloadpage: (nsarray *) args {     nsstring *pageindex = [args objectatindex:0];         nsstring *firstcase = [args objectatindex:1];     } 

got answer question


Comments