Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8674957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:50:03+00:00 2026-06-12T19:50:03+00:00

My app is to create csv file and send it through mail. But when

  • 0

My app is to create csv file and send it through mail. But when I discard mail, I’m getting black screen. The previous view is not appearing and is being covered by the black screen. I viewed various questions and answers in stack overflow. But nothing seems to be working.

- (IBAction)openMail:(id)sender
{
    [self getdata];

    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"BMNET- Travel Log"];




        NSString *CSVstring=@"Name, StartingDateNTime, EndingDateNTime, TravelType, DistanceTravelled, Amount\n" ;

        NSString *CSVPath,*record;;

        NSString  *temporayCSV= @"" ;

           for (int i=0; i<[getAmount count]; i++) {    

               record = [NSString stringWithFormat:@"%@, %@, %@, %@, %@, %@", [getName objectAtIndex:i],   [getStartDate objectAtIndex:i],   [getEndDate objectAtIndex:i],[getType objectAtIndex:i],[getDistance objectAtIndex:i],[getAmount objectAtIndex:i]];



                      NSLog(@"%d",i);

                      temporayCSV = [NSString stringWithFormat:@"%d  %@  \n ",(i+1),record];

                      CSVstring = [CSVstring stringByAppendingFormat:temporayCSV];       
                      NSLog(@"%@",CSVstring);

          }

        NSArray *paths = NSSearchPathForDirectoriesInDomains(
                                                             NSDocumentDirectory, NSUserDomainMask, YES); 
        NSString *documentsDirectory = [paths objectAtIndex:0]; 

        NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil];
        [mailer setToRecipients:toRecipients];
        CSVPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.csv", @"CSV_FormatedTable"]];
        NSFileManager *fileManager;
        //add our file to the path
        [fileManager createFileAtPath:CSVPath contents:[CSVstring dataUsingEncoding:NSUTF8StringEncoding] attributes:nil];
        NSData *rolesCSVData =[NSData dataWithContentsOfFile:CSVPath];
        NSLog(@"The data is %@",CSVstring);

        //create my data to append
        NSFileHandle *handle;
        handle = [NSFileHandle fileHandleForWritingAtPath: CSVPath ]; 
        //say to handle where's the file fo write
        [handle truncateFileAtOffset:[handle seekToEndOfFile]]; 
        //position handle cursor to the end of file
        [handle writeData:[data dataUsingEncoding:NSUTF8StringEncoding]];   
        //write data to with the right encoding






        [mailer addAttachmentData:rolesCSVData mimeType:@"text/csv" fileName:@"Log"];
        NSString *emailBody = @"Attachment of Log";
        [mailer setMessageBody:emailBody isHTML:NO];
        [self presentModalViewController:mailer animated:YES];
        mailer.modalPresentationStyle = UIModalPresentationPageSheet;

    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {

        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");

            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");

            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");

            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");

            break;
        default:
            NSLog(@"Mail not sent.");

            break;
    }
    // Remove the mail view

    [self dismissModalViewControllerAnimated:YES];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:50:04+00:00Added an answer on June 12, 2026 at 7:50 pm

    presentModalViewController:animated: and dismissModalViewControllerAnimated: are deprecated as of iOS6, just as a side note!
    which iOS versions are you targeting for and is this a iPhone or iPad application you’re working on?

    beside that i noticed the following:

    [self presentModalViewController:mailer animated:YES];
    mailer.modalPresentationStyle = UIModalPresentationPageSheet;
    

    you’re setting the modalPresentationStyle after you’ve presented the view controller!
    move the line mailer.modalPresentationStyle = UIModalPresentationPageSheet; before the presentModalViewController line. Maybe this is the problem!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my rails 3 app I use fastercsv to create a csv file to
I've got this command line app that iterates through CSV files to create a
I have a PHP app that creates a CSV file which is forced to
I need my app to create a dialog Seekbar. But I cannot make it
I have create web app in MVS 3 but failed to display alert message
I've been asked to output a CSV file from a view in MySQL. The
How can I create a text file (an Excel-compatible CSV file), add some text
In my app, I generate a UTF8-encoded CSV file with CHCSVWriter and display it
I want to send a csv file from Android to Python AppEngine. I'm using
I'm building a simple php app using OOP that creates a CSV file based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.