Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>try <code>[mailer addAttachmentData:myData mimeType:@"text/csv" fileName:@"expenses.csv"];</code></p> <p><strong>Edit:</strong> This is the code I'm using in my app:</p> <pre><code>- (IBAction) ExportData:(id)sender { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *filePath = [documentsDirectory stringByAppendingPathComponent:kExportFileName]; self.timeRecords = [[NSMutableArray alloc] init]; for (int i=0; i&lt; [self.selectedTimeEntries count]; i++) for (int j=0; j&lt;[[self.selectedTimeEntries objectAtIndex:i] count]; j++) if ([[self.selectedTimeEntries objectAtIndex:i] objectAtIndex:j] == [NSNumber numberWithBool:YES]) [self.timeRecords addObject:[self timeEntriesForDay:[self.uniqueArray objectAtIndex:i] forIndex:j]]; if( !([self.timeRecords count]!=0)) { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"There are no time entries selected!" message:@"Please select at least one time entry before proceeding" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; return; } NSMutableString *csvLine; NSError *err = nil; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSString *dateString = nil; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; [numberFormatter setPositiveFormat:@"###0.##"]; NSString *formattedNumberString = nil; if(![[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil]; } for (timeEntries *timeEntry in self.timeRecords) { csvLine = [NSMutableString stringWithString:timeEntry.client]; [csvLine appendString:@","]; [csvLine appendString:timeEntry.category]; [csvLine appendString:@","]; [csvLine appendString:timeEntry.task]; [csvLine appendString:@","]; dateString = [dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:timeEntry.date]]; [csvLine appendString:dateString]; [csvLine appendString:@","]; formattedNumberString = [numberFormatter stringFromNumber:timeEntry.duration]; [csvLine appendString:formattedNumberString]; [csvLine appendString:@","]; [csvLine appendString:timeEntry.description]; [csvLine appendString:@"\n"]; if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { NSString *oldFile = [[NSString alloc] initWithContentsOfFile:filePath]; [csvLine insertString:oldFile atIndex:0]; BOOL success =[csvLine writeToFile:filePath atomically:NO encoding:NSUTF8StringEncoding error:&amp;err]; if(success){ } [oldFile release]; } } if (!appDelegate.shouldSendCSV) { self.csvText = csvLine; } if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { [self emailExport:filePath]; } self.selectedTimeEntries =nil; self.navigationController.toolbarHidden = NO; } - (void)emailExport:(NSString *)filePath { NSLog(@"Should send CSV = %@", [NSNumber numberWithBool:appDelegate.shouldSendCSV]); MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self; // Set the subject of email [picker setSubject:@"My Billed Time Export"]; // Add email addresses // Notice three sections: "to" "cc" and "bcc" NSString *valueForEmail = [[NSUserDefaults standardUserDefaults] stringForKey:@"emailEntry"]; NSString *valueForCCEmail = [[NSUserDefaults standardUserDefaults] stringForKey:@"ccEmailEntry"]; if( valueForEmail == nil || [valueForEmail isEqualToString:@""]) { UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please set an email address before sending a time entry!" message:@"You can change this address later from the settings menu of the application!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; return; } else { [picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]]; } if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:@""]) { [picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]]; } // Fill out the email body text NSString *emailBody = @"My Billed Time Export File."; // This is not an HTML formatted email [picker setMessageBody:emailBody isHTML:NO]; if (appDelegate.shouldSendCSV) { // Create NSData object from file NSData *exportFileData = [NSData dataWithContentsOfFile:filePath]; // Attach image data to the email [picker addAttachmentData:exportFileData mimeType:@"text/csv" fileName:@"MyFile.csv"]; } else { [picker setMessageBody:self.csvText isHTML:NO]; } // Show email view [self presentModalViewController:picker animated:YES]; // Release picker [picker release]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload