我现在有点卡住了。首先,我对ios和objective-c有点陌生,我正在尝试实现一个功能,我需要将多个pdf文件发送到一封电子邮件,而不使用mailpickercontroller,而是使用NSURLConnection。截至目前,此代码可以向这些 pdf 文件中的每一个发送邮件,如果有人计划在他们的电子邮件中发送 100 个 pdf,这是非常糟糕的
NSString *defaultEmail = [config objectForKey:@"DEFAULT_EMAIL"];
NSArray *badgeDataLists = [self getBadgeDatas]; //list of nsdata from the pdf file
if ([NSURLConnection instancesRespondToSelector:@selector(originalRequest)] && defaultEmail && ![defaultEmail isEqualToString:@""])
{
NSString * email = defaultEmail;
NSString * path = [NSString stringWithFormat:@"http://app.receptionsignin.com/mail_notification.php?key=k6j3h5u6nvh3i5jsl60ao5uqjgmso4u1&type=badge&email=%@&for=%@", email, @"All Here to See people", nil];
for (NSData *badgeData in badgeDataLists){
NSMutableURLRequest * req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
[req setHTTPMethod:@"POST"];
[req setHTTPBody:badgeData];
[req addValue: @"application/pdf" forHTTPHeaderField:@"Content-Type"];
[req addValue: [NSString stringWithFormat:@"%d", badgeData.length] forHTTPHeaderField:@"Content-Length"];
NSLog(@"Content %@", [[NSString alloc] initWithData:[req HTTPBody] encoding:NSUTF8StringEncoding]);
[NSURLConnection sendAsynchronousRequest:req queue:nil completionHandler:nil];
}
}
我已经尝试按照这个链接这个、这个和那个,基本上它涉及这个“边界”和“多个/表单数据”。我确实遵循了这些提示并且我能够收到邮件,但它没有附带附件,所以......是的,我需要这方面的帮助