CHCSV问题通过邮件发送

时间:2012-10-17 11:06:33

标签: iphone objective-c export-to-csv

我想从我的SQLite3数据库写一个CSV文件,然后通过电子邮件发送...编写我的CSV文件我使用以下功能:

- (void) exportCSV {

FMDatabase *dbb = [[FMDatabase alloc] initWithPath:[self getDBPath]];
if (![dbb open]) {
    //couldn't open the database
    [dbb release];
}
FMResultSet *results = [dbb executeQuery:@"SELECT * FROM Daten"];
CHCSVWriter *csvWriter = [[CHCSVWriter alloc] initWithCSVFile:[self getCSVPath] atomic:NO];
while([results next]) {
    NSDictionary *resultRow = [results resultDictionary];
    NSArray *orderedKeys = [[resultRow allKeys] sortedArrayUsingSelector:@selector(compare:)];
    //iterate over the dictionary
    for (NSString *columnName in orderedKeys) {
        id value = [resultRow objectForKey:columnName];
        [csvWriter writeField:value];
    }
    [csvWriter writeLine];
}
[csvWriter closeFile];
[csvWriter release];

[dbb close];
[dbb release];


}

这是我通过Mail发送csv的功能:

- (void)actionEmailComposer {

if ([MFMailComposeViewController canSendMail]) {

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:@"Subject Goes Here"];
     [mailViewController setMessageBody:@"Your message goes here" isHTML:NO];
    mailViewController.navigationBar.tintColor = [UIColor blackColor];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Speed" ofType:@"csv"];
    NSData *myData = [NSData dataWithContentsOfFile:filePath];

    NSString *fileName = @"Speed.csv";

            [mailViewController addAttachmentData:myData mimeType:@"text/csv" fileName:fileName];

      [self presentViewController:mailViewController animated:YES completion:nil];
      [mailViewController release];

      }

      else {

          NSLog(@"Device is unable to send email in its current state.");

      }

      }

问题是,我的邮件没有附件......其他附件如png,jpg甚至txt没有任何问题!

0 个答案:

没有答案