CSV未附加到应用程式电子邮件中? [英] CSV not attaching to in app email?

查看:163
本文介绍了CSV未附加到应用程式电子邮件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有这个问题有一段时间,只是不能得到它的工作!我一直在建立一个调查应用程序,用户只需输入信息,并将其保存到csv文件。现在在我需要将应用程序中的csv文件附加到电子邮件地址的阶段...

So I have had this problem for sometime and just cant get it working! I have been building a survey app that users simply enter information in and its saved to a csv file. Im now at the stage where I need to attached the csv file within the app to an email address...

我刚在新的i-phone上测试了这个在收到电子邮件时没有附件?它在邮件应用程序和模拟器中,但是当消息接收到电子邮件帐户附件已经走了?任何人都可以帮助?我的代码如下:

I just tested this on my new i-phone and there is no attachment when the email is received? Its there in the mail app and in the simulator, however when the message is received on the email account the attachment has gone? Can anyone help?? My code is below:

- (IBAction)send:(id)sender {

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *savedFilePath = [documentsDirectory stringByAppendingPathComponent:@"result‌s.csv"];
    NSData *csvData = [NSData dataWithContentsOfFile:savedFilePath];

    MFMailComposeViewController *mailcomposer = [[MFMailComposeViewController alloc] init];
    [mailcomposer addAttachmentData:csvData mimeType:@"text/csv" fileName:@"results.csv"];
    [mailcomposer setToRecipients:@[@"gpsflighttrial@gcap.eu"]];
    [mailcomposer setSubject:self.subject.text];
    [mailcomposer setMessageBody:self.message.text isHTML:NO];
}


推荐答案

很多尝试不同的方式我终于找到了与朋友一起工作的方式(见下面的代码)

So after many sleepless nights and a lot of trying different ways I finally found the way that works with a friend (see code below)

 NSString *docsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSData *attachment = [NSData dataWithContentsOfFile:[docsDirectory stringByAppendingPathComponent:@"results.csv"]];

    MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
    mailer.mailComposeDelegate = self;
    [mailer setToRecipients:@[@"gpsflighttrial@gcap.eu"]];
    [mailer setSubject:self.subject.text];
    [mailer setMessageBody:self.message.text isHTML:NO];
    [mailer addAttachmentData:attachment mimeType:@"application/csv" fileName:@"results.csv"];
    [self presentModalViewController:mailer animated:YES];

只是为了防止将来出现此问题。

Just in case anyone has this problem in the future.

这篇关于CSV未附加到应用程式电子邮件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆