我正在保存文件文档目录,之后我想通过电子邮件发送该文件,但问题是它没有附加我认为问题是由于路径冲突或其他任何东西是我保存文件的代码。
// 从 iOS 设备检索文档目录
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// 指示可变数据对象将其上下文写入磁盘上的文件
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
这是我用于在电子邮件中发送此文件的代码
- (NSString *)pathForFile : (NSString *) fileName{
return [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent: fileName];
}
- (void) sendMailWithAttachedFile : (NSString *) fileName :(NSString *) extension{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
// NSURL* outputURL = [[NSURL alloc] initFileURLWithPath:[self pathForResourse:fileName ofType:extension]];
NSURL* outputURL = [[NSURL alloc] initFileURLWithPath:[self pathForFile:[NSString stringWithFormat:@"%@.%@", fileName, extension]]];
NSData *data=[[NSData alloc]initWithContentsOfURL:outputURL];
[picker addAttachmentData:data mimeType:@"documents/pdf" fileName:@"TestOne.pdf"];
[self presentModalViewController:picker animated:YES];
}
-(IBAction)onEmailResultPDF{
[self sendMailWithAttachedFile:@"TestOne":@"pdf"];
}