I've seen several questions before such as this but for the lack of an accepted answer as well as having implemented everything as needed I still continue to face the issue as follows:
I display the mail composer but on clicking cancel, the composer view freezes. I think this is due to the Save/Delete draft action sheet showing up out of the visible frame. Yes I have set the mailComposeDelegate to the presenting view controller and have read up on several similar questions where user's have not handled the (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
delegate to dismiss the composer on cancel. I have handled that as well but I cant seem to figure out for the life of me why the action sheet wont show up in the visible area of the screen in the iPhone version of my universal app. The view frame of the viewcontroller modally presenting the mail composer as NSLogged is (0,0,320,480). My app is universal & the mail composer works perfectly on the iPad. Below is a screenshot of how the composer view looks, running on iPhone Simulator 5.1:-
Here's the code to display the composer:
-(IBAction)mailButtonPressed:(id)sender {
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"Subject"];
[controller setMessageBody:@"Test" isHTML:YES];
[controller setToRecipients:nil];
if(controller) {
[self presentModalViewController:controller animated:YES];
[controller release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
Why not try removing the code, and retrying while following a tutorial online such as this one:
http://iphonedevsdk.com/forum/tutorial-discussion/43633-quick-tutorial-on-how-to-add-mfmailcomposeviewcontroller.html
In cases like these, you always forget the one simple line of code needed to work so following a tutorial helps me make sure all the code necessary is there.
Try this code instead:
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}
Use this whole code here for the message:
.h
#import <MessageUI/MFMailComposeViewController.h>
@interface EmailViewController : UIViewController<MFMailComposeViewControllerDelegate>
.m
-(IBAction)Email {
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]];
[composer setSubject:@"Idea for Basic Calculator"];
[composer setMessageBody:@"My idea is:" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:composer animated:YES];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error with message" message:[NSString stringWithFormat:@"Error %@", [error description]] delegate:nil cancelButtonTitle:@"Try Again Later!" otherButtonTitles:nil, nil];
[alert show];
[self dismissModalViewControllerAnimated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With