全部,在我的要求中需要发送带有附件文本文件的邮件,该文件位于文档目录中,在这里我可以获取文档目录中的文件路径,如何从我的 ipad 附加文件以发送。
这是我尝试过的代码
MFMailComposeViewController *picker=[[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate=self;
if ([MFMailComposeViewController canSendMail]){
// Create and show composer
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSLog(@"directry path %@",paths);
NSString *fullPath = [[paths lastObject] stringByAppendingPathComponent:@"Logs/log-858743.txt"];
NSLog(@"directry full path %@",fullPath);
NSData *data = [NSData dataWithContentsOfFile: fullPath];
NSLog(@"Data value %@",data);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
if (fileExists) {
NSLog(@"file is there");
}else{
NSLog(@"file is not there");
}
[picker setSubject:@"Backup"];
[picker addAttachmentData:data mimeType:@"text/rtf" fileName:@"log.txt"];
[picker setMessageBody:@"testing." isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release]; }
else{
// Show some error message here
}