mfmailcomposeviewcontrollerios7-statusbar

iOS 7 MFMailComposeViewController status bar color


Converting a legacy app for iOS 7. Have most of the problems covered, but we have a feature that emails an error log using MFMailComposeViewController, and the status bar is coming up black on black in that view.

The status bar text color is set to white globally using plist settings, and that seems to handle everything else just fine. Only the email VC is acting up. (We present it using presentModalViewController.)

Has anyone figured out how to crack this nut?

Update: Tried subclassing MFMailComposeViewController and implementing preferredStatusBarStyle, but it's not invoked, even after setting "View controller-based status bar" to YES in the plist.


Solution

  • The following kluge appears to do the job:

            // Present the email controller.  The delegate will dismiss it.
    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000
            float systemVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
            if (systemVersion < 7.0f) {
                [viewController presentViewController:emailController animated:YES completion:^{}];
            }
            else {
                // Need a song and dance to get the header bar to show correctly.  (And presentModalViewController is deprecated anyway.)  Note that this code doesn't actually change the email controller's header, but it somehow lets the header below "show through" when it wouldn't otherwise.  (I know -- like many of the iOS 7 fixes this makes no sense.  But it works.  (So far.))
    #warning Sometimes produces console message "Presenting view controllers on detached view controllers is discouraged <XxxxViewController: 0xc658a70>"
                [viewController presentViewController:emailController animated:YES completion:^{
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
                    if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
                        && [[UIApplication sharedApplication] respondsToSelector:NSSelectorFromString(@"setStatusBarStyle:")]) {
                        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
                    }
    #endif
                }];
            }
    
    #else
            [viewController presentModalViewController:emailController animated:YES];
    #endif