我正在从 iphone 应用程序发送电子邮件,它工作正常,但我希望通过电子邮件附加一个 pdf 文件,该文件是应用程序的文档文件夹。为了测试,我首先从应用程序的资源文件夹中附加了一个 png,但它没有附加并且未通过电子邮件发送我正在使用以下代码。
- (IBAction)onEmailResult
{
if ([[MFMailComposeViewController class] canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Pig Game"];
[picker setToRecipients:toRecipients];
int a=10;
int b=100;
NSString *path = [[NSBundle mainBundle] pathForResource:@"project existing photo" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"png" fileName:@"icon.png"];
NSString * emailBody = [NSString stringWithFormat:@"My Score %d",a];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
else {
int a=10;
int b=20;
NSString *recipients = @"mailto:imran_husain_2000@yahoo.com?&subject=Pig Game";
NSString *body = [NSString stringWithFormat:@"&body=My Score: %d/%d, My Time: %@", a,b, time];
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
}