在我的应用程序中,我使用 ASIFormDataRequest 发送我的新用户注册请求。该请求包含用户详细信息以及使用 base64Encoding 转换的图像。我也得到了回应。但应用程序在收到响应后崩溃。请帮我解决这个问题。这段代码有什么错误吗?
NSString *sx=@"male";
registrationStatusBlock = response;
NSDateFormatter *dateOfBirthFormatter = [[NSDateFormatter alloc] init];
[dateOfBirthFormatter setDateFormat:@"YYYY:MM:dd"];
[dateOfBirthFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSString *formattedDate = [dateOfBirthFormatter stringFromDate:userDetails.dateOfBirth];
NSLog(@"URL: %@", [NSString stringWithFormat:@"%@&firstName=%@&lastName=%@&password=%@&emailId=%@&portrait=%@&dob=%@&gender=%@&task=createUser",webServiceURL,userDetails.firstName, userDetails.lastName, userDetails.emailAddress, userDetails.password, userDetails.profilePicture, formattedDate, sx]);
NSLog(@"Gender %@",userDetails.gender);
int lengthOfData=0;
NSString *encodedString ;
NSData * imageData = UIImagePNGRepresentation(userDetails.profilePicture);
registrationStatusBlock = response;
self.responseData = [NSMutableData data];
if(userDetails.profilePicture !=NULL)
{
lengthOfData = imageData.length;
encodedString = [NSString base64StringFromData:(NSData *) imageData length:lengthOfData];
}
else
encodedString=@"";
NSLog(@"URL: %@", [NSString stringWithFormat:@"%@&firstName=%@&lastName=%@&password=%@&emailId=%@&portrait=%@&portrait_type=png&dob=%@&gender=%@&task=createUser",webServiceURL,userDetails.firstName, userDetails.lastName, userDetails.emailAddress, userDetails.password, encodedString, formattedDate, sx]);
NSMutableString *URLString = [[NSMutableString alloc]initWithString:webServiceURL];
[URLString appendString:[NSString stringWithFormat:@"%@&firstName=%@&lastName=%@&password=%@&emailId=%@&portrait=%@&portrait_type=png&dob=%@&gender=%@&task=createUser",webServiceURL,userDetails.firstName, userDetails.lastName, userDetails.emailAddress, userDetails.password, encodedString, formattedDate, sx]];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[webServiceURL stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
[request addPostValue:userDetails.firstName forKey:@"firstName"];
[request addPostValue:userDetails.lastName forKey:@"lastName"];
[request addPostValue:userDetails.password forKey:@"password"];
[request addPostValue:userDetails.emailAddress forKey:@"emailId"];
[request addPostValue:encodedString forKey:@"portrait"];
[request addPostValue:@"png" forKey:@"portrait_type"];
[request addPostValue:formattedDate forKey:@"dob"];
[request addPostValue:sx forKey:@"gender"];
[request addPostValue:@"createUser" forKey:@"task"];
[request setRequestMethod:@"POST"];
NSLog(@" user registration request %@",request);
[request setDelegate:self];
[request startAsynchronous];
[NSThread sleepForTimeInterval:5];
NSLog(@"response %@",[request responseString]);
registrationStatusBlock =[[request responseString]JSONValue];