我正在将一些数据从我的应用程序发送到服务器。我的数据由不同的字段组成,如下所示我的代码
-(void)createXML
{
xmlStr = @"<?xml version='1.0'?>\n<jand_req>\n<inquiryList>\n<productArr>\n";
NSString *nameStr=[NSString stringWithFormat:@"<name>%@</name>\n",name.text];
xmlStr=[xmlStr stringByAppendingString:nameStr];
NSString *compNameStr=[NSString stringWithFormat:@"<comp_name>%@</comp_name>\n",compName.text];
xmlStr=[xmlStr stringByAppendingString:compNameStr];
NSString *cityStr=[NSString stringWithFormat:@"<city>%@</city>\n",city.text];
xmlStr=[xmlStr stringByAppendingString:cityStr];
NSString *countryStr=[NSString stringWithFormat:@"<country>%@</country>\n",[nameToCode objectForKey:country.text]];
xmlStr=[xmlStr stringByAppendingString:countryStr];
NSString *commentsStr=[NSString stringWithFormat:@"<comment>%@</comment>\n",commentsBox.text];
xmlStr=[xmlStr stringByAppendingString:commentsStr];
xmlStr=[xmlStr stringByAppendingString:@"</userDetail>\n</inquiryList>\n</jand_req>"];
}
在此之后,我将上述数据发送到服务器,如下所示
- (void)submitForm
{
[self createXML];
NSLog(@"myaccesscode%@",[fn getValFromSettings:@"accessCode"]);
NSString *serviceUrlStr=[NSString stringWithFormat:@"%@/%@/API_sendmail.php?access_code=%@",domainName,apiFolderPath,[fn getValFromSettings:@"accessCode"]];
NSLog(@"%@",serviceUrlStr);
NSURL * serviceUrl = [NSURL URLWithString:[serviceUrlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest * serviceRequest = [NSMutableURLRequest requestWithURL:serviceUrl cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:100];
[serviceRequest setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[serviceRequest setHTTPMethod:@"POST"];
[serviceRequest setHTTPBody:[xmlStr dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn=[[[NSURLConnection alloc] initWithRequest:serviceRequest delegate:self startImmediately:YES] autorelease];
}
以上所有代码对我来说都很好,但现在我想在此代码中包含另一个功能,其中包含发件人电子邮件地址,但此发件人电子邮件必须从设备中获取,与我们在应用程序中使用 MFMailComposeViewController 时相同,然后自动获取从设备获取发件人电子邮件地址。任何帮助将不胜感激。