我在我的应用程序中附加或创建 .csv 文件时遇到问题,我无法确定问题所在。在电子邮件视图中显示 .csv 附件,但收到电子邮件时没有附件。我将一组对象 (dataController.masterList) 发送到 CHCSVWriter。本周我花了很多时间尝试解决有关电子邮件附件和 CHCSVWriter 的其他问题的解决方案,显然没有一个解决方案有效,所以知道我在问你。问题出在哪里,你有什么建议?提前谢谢你,快乐的日子,-Rob
- (IBAction)send:(id)sender {
static NSDateFormatter *formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
NSString *filepath = @"testfile.csv";
filepath = [filepath stringByExpandingTildeInPath];
NSOutputStream *exportStream = [NSOutputStream outputStreamToFileAtPath:filepath append:NO];
NSStringEncoding encodingA = NSUTF8StringEncoding;
CHCSVWriter *csvWriter = [[CHCSVWriter alloc] initWithOutputStream:exportStream encoding:encodingA delimiter:','];
[csvWriter writeField:[NSString stringWithFormat:@"One"]];
[csvWriter writeLineOfFields:dataController.masterList];
[csvWriter closeStream];
NSString *path = [[NSBundle mainBundle] pathForResource:filepath ofType:@".csv"];
NSData *mydata = [NSData dataWithContentsOfFile:path];
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[mail setMailComposeDelegate:self];
[mail setSubject:@"CSV File"];
[mail addAttachmentData:mydata mimeType:@"text/csv" fileName:filepath];
[mail setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:mail animated:YES completion:nil];
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];