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

  • SEARCH
  • Home
  • 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 8369461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:39:01+00:00 2026-06-09T13:39:01+00:00

I noticed that I am using the mail functionality several time so I decided

  • 0

I noticed that I am using the mail functionality several time so I decided to make an independent Class for functions that get repeated several time instead of copy-pasting the code several times

the class get successfully called and the e-mail function get successfully called as well but the e-mail client of the phone does not appear after the function is called

here is my code

in the main class I do the following call

-(void)emailFunction{
...

CommonlyUsed Email = [[CommonlyUsed alloc] init];
[Email sendMail:receipient :CC :BCC :subject :body];

...
}

in my CommonlyUsed.h I have the following IDEs called :

#import <UIKit/UIKit.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MessageUI/MessageUI.h>


@interface CommonlyUsed : UIViewController <MFMailComposeViewControllerDelegate>{

in CommonlyUsed.m I have the following :

-(void)sendMail:(NSString*)receipient:(NSString*)cc:(NSString*)bcc:(NSString*)subject:(NSString*)body{

 MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
    [ composer setMailComposeDelegate:self];

 if ( [MFMailComposeViewController canSendMail]){
if (receipient) {
            [composer setToRecipients:[NSArray arrayWithObjects:receipient, nil]];
        }

        if (cc) {
            [composer setCcRecipients:[NSArray arrayWithObjects:receipient, nil]];
        }

        if (bcc) {
            [composer setBccRecipients:[NSArray arrayWithObjects:receipient, nil]];
        }

        if (subject) {
             [composer setSubject:subject];
        }

 [composer setMessageBody:body isHTML:HTMLBody];

        [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];

        [self presentModalViewController:composer animated:YES];
        }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    if(error){
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"error" message:[NSString stringWithFormat:@"error %@", [error description]] delegate:nil cancelButtonTitle:@"dismiss" otherButtonTitles:nil, nil];
        [alert show];
        [self dismissModalViewControllerAnimated:YES];
    }
    else{
        [self dismissModalViewControllerAnimated:YES];
    }

    }

the code compiles and runs without errors what am I missing ??

  • 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-09T13:39:03+00:00Added an answer on June 9, 2026 at 1:39 pm

    Instead of doing this:

    [self presentModalViewController:composer animated:YES];

    do this:

    [[[[[UIApplication sharedApplication] delegate] window] rootViewController] presentModalViewController:composer animated:YES];

    or this:

    [[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:composer animated:YES];

    Your class Email is not currently an active view controller so it can’t present a modal view controller, you need to use an active one, like the rootViewController of the main UIWindow.

    EDIT:

    If your using ARC by the time the emailClient gets dismissed your object(delegate) would have been removed from memory, so a solution is to make the CommonlyUsed class a Singleton:

    +(CommonlyUsed *)sharedInstance {
    
        static CommonlyUsed * cu = nil;
    
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
    
            cu = [[CommonlyUsed alloc] init];
    
        });
    
        return cu;
    }
    

    So you would use it this way:

    CommonlyUsed * email = [CommonlyUsed sharedInstance];
    [email sendMail:receipient :CC :BCC :subject :body];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using PHP mail() to send daily notice emails. But I noticed that
I'm using google chrome and I noticed that every time I do an XHR
I just started using Qt and noticed that it uses its own make tool,
I just started using Qt and noticed that all the example class definitions have
I just noticed that the email sent from my host using mail() function also
I am using this expression to validate e-mail addresses: ^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$ I noticed that in
I noticed when using the Google Chat feature from your Google Mail that you
I've noticed that the majority of the example code using .NET's SmtpClient class don't
I noticed that when using a FragmentPagerAdapter the Fragments that are non-adjacent to the
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,

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.