Configure MFMailComposeViewController in iOS7

I'm having trouble setting up MFMailComposeViewController in iOS7. I am trying to hide and remove the header because I have a custom navigation view that I want to transfer completely to the mail view controller. I use this and it works great on iOS6, but doesn't work the first time on iOS7. When I open the view and cancel the mail, and then open the controller again, it works. The problem is the first view of the mail controller. Here is the code I'm using:

if ([MFMailComposeViewController canSendMail]) {

    UIView* parentView = [self showProgress];

    MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
    controller.mailComposeDelegate = self;

    if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
        [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor lightGrayColor], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"CourierNewPS-BoldMT" size:1], UITextAttributeFont, [UIColor whiteColor],UITextAttributeTextColor, nil]];

    [controller setToRecipients:[NSArray arrayWithObject:[LNController shared].profile.email]];
    [controller setSubject:NSLocalizedString(@"APPSTORE_NAME", nil)];
    NSData* energyData = [[self createEnergyCSVFile] dataUsingEncoding:NSUTF8StringEncoding];
    NSData* timeData = [[self createTimeCSVFile] dataUsingEncoding:NSUTF8StringEncoding];
    [controller addAttachmentData:energyData mimeType:@"text/csv" fileName:NSLocalizedString(@"ENERGY", nil)];
    [controller addAttachmentData:timeData mimeType:@"text/csv" fileName:NSLocalizedString(@"TIME", nil)];

    [[[[controller viewControllers] lastObject] navigationItem] setTitle:@""];
    [self presentViewController:controller animated:YES completion:nil];

    [self hideProgress:parentView];

}  

Has anyone experienced this before? Any help would be awesome.

+3
source share
1 answer

MFMailComposeViewController. :

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    // Fix UI -- Add your custom UI here
    [mailViewController.navigationBar setTintColor:[UIColor whiteColor]];
    [mailViewController.navigationBar setBarTintColor:[UIColor whiteColor]];
    // Set params
    [mailViewController setToRecipients:@[@"e-mail@email.com"]];
    [mailViewController setSubject:NSLocalizedString(@"Feedback", @"Feedback")];
    [self presentViewController:mailViewController animated:YES completion:^{
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    }];
}

EDIT: iOS 7, , iOS 6

+5

All Articles