【发布时间】:2013-12-16 07:20:11
【问题描述】:
我对 IoS 比较陌生,在使用邮件附件时遇到问题。下面是我的代码。
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt",
documentsDirectory];
//create content - four lines of text
NSString *content = @"One\nTwo\nThree\nF\nFive";
//save content to the documents directory
[content writeToFile:fileName
atomically:NO
encoding:NSStringEncodingConversionAllowLossy
error:nil];
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"Test mail"];
NSData *myData = [NSData dataWithContentsOfFile:fileName];
[mailComposer addAttachmentData:myData mimeType:@"text/plain" fileName:fileName];
[mailComposer setMessageBody:@"Testing message for the test mail" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
这很好用,我收到了邮件附件。但是,如果我将文件名更改为
NSString *fileName = [NSString stringWithFormat:@"%@",
@"Sample.txt"];
在撰写邮件中显示附件,但发送时不会有任何附件。任何人都可以建议如何完成同样的事情
【问题讨论】:
标签: iphone ios7 email-attachments mfmailcomposeviewcontroller