直接sqliteをcsvに変換することはできません。まず、すべてのデータベースデータを取得し、csvファイルに書き込みます。以下の例を使用してcsvを作成し、送信します。
NSString *csvString =@"1,2 , 3 , 4, 5 ,6 , 7";
for(int i=0;i<rangeData.count ;i++)
{
NSArray *temp = [di timeCalculation:[[rangeData objectAtIndex:i] objectForKey:@""] :[[rangeData objectAtIndex:i] objectForKey:@""]];
NSString *strTemp =[NSString stringWithFormat:@"%@,%@,%@,%@,%@,%@,%@",
[NSString stringWithFormat:@"%@",[simpleDate stringFromDate:[[NSDate alloc]initWithTimeIntervalSince1970:[[[rangeData objectAtIndex:i] objectForKey:@""] floatValue]]]],
[NSString stringWithFormat:@"%@",[shrotDate stringFromDate:[[NSDate alloc]initWithTimeIntervalSince1970:[[[rangeData objectAtIndex:i] objectForKey:@""] floatValue]]]],
[NSString stringWithFormat:@"%@",[shrotDate stringFromDate:[[NSDate alloc]initWithTimeIntervalSince1970:[[[rangeData objectAtIndex:i] objectForKey:@""] floatValue]]]],
[NSString stringWithFormat:@"%@",[shrotDate stringFromDate:[[NSDate alloc]initWithTimeIntervalSince1970:[[[rangeData objectAtIndex:i] objectForKey:@""] floatValue]]]],
[NSString stringWithFormat:@"%@",[shrotDate stringFromDate:[[NSDate alloc]initWithTimeIntervalSince1970:[[[rangeData objectAtIndex:i] objectForKey:@""] floatValue]]]],
[NSString stringWithFormat:@"%@",[[temp objectAtIndex:0] stringByReplacingOccurrencesOfString:@": " withString:@""]] ,
[NSString stringWithFormat:@"%@",[[temp objectAtIndex:1] stringByReplacingOccurrencesOfString:@" : " withString:@""]]];
csvString = [NSString stringWithFormat:@"%@ \n %@",csvString,strTemp];
}
//create instance of NSFileManager
NSFileManager *fileManager = [NSFileManager defaultManager];
//create an array and store result of our search for the documents directory in it
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//create NSString object, that holds our exact path to the documents directory
NSString *documentsDirectory = [paths objectAtIndex:0];
NSLog(@"Document Dir: %@",documentsDirectory);
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv", @"userdata"]]; //add our file to the path
[fileManager createFileAtPath:fullPath contents:[csvString dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
NSData *csvData =[NSData dataWithContentsOfFile:fullPath];
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:@""]];
[controller setSubject:@"CSV Export"];
[controller setMessageBody:@"" isHTML:NO];
[controller addAttachmentData:csvData mimeType:@"text/csv" fileName:@"userdata.csv"];
[self presentModalViewController:controller animated:YES];
[controller release];