Search code examples
objective-cmfmailcomposeviewcontroller

presentViewController is not showing mail composer sheet


presentViewController is not showing the mail modalview controller. I have changed from presentmodalviewcontroller to presentViewController, but it was not giving any error nor it is presenting the modalview. How to fix this issue?

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self; 
    picker.navigationBar.tintColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness:0.69 alpha:0];
    NSString *lObjstringPtr = (NSString *)nil;

    if(OPPORTUNITY_ENTITY_OBJECT_TYPE_CODE==m_cobjOwningGroup.m_cObjSelectedEntity.m_cObjectTypeCode) {
        lObjstringPtr = [lObjstringPtr stringByAppendingFormat:@" To Follow Up"];
        [picker setSubject:lObjstringPtr];
        lObjstringPtr = (NSString *)nil;
    } else 
        [picker setSubject:@""];

        [picker setMessageBody:m_cObjemailBodyStrPtr isHTML:NO];
        NSArray *toRecipients = [NSArray arrayWithObject:pEmailID];
        [picker setToRecipients:toRecipients];
        [self presentViewController:picker animated:YES completion:nil]; 
        [picker release];

Solution

  • Two things, one specific to this case, one a general point.

    1. You don't appear to be checking whether mail is set up on your device. Before you try to display the mail view you should check the return value of [MFMailComposeViewController canSendMail] and only show the controller if it's YES
    2. A common case for a view not showing is that the controller is nil. Before presentViewController: you might want to check (with an NSLog or using a debugger) that picker is not zero.