Composing mail in iOS 7 : Assertion failure in -[MFComposeSubjectView layoutSublayersOfLayer:]
Asked Answered
T

4

6

I am currently running in troubles with iOS7 and the MFMailComposeViewController. Sometimes (quite often but not always), I have the following crash when presenting the MFMailComposeViewController:

** * Assertion failure in -[MFComposeSubjectView layoutSublayersOfLayer:], /SourceCache/UIKit/UIKit-2903.23/UIView.m:8540

Here is how I present the controller:

if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController* mailVC = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
        mailVC.mailComposeDelegate = self;

        [mailVC setSubject:@"blablabla"]];
        [mailVC setMessageBody:@"blablabla" isHTML:NO]; 
        mailVC.modalPresentationStyle = UIModalPresentationFormSheet;
        mailVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

        if(isIpad) {
            [sharedParentViewController presentViewController:mailVC animated:YES completion:nil];
        } else {
            [sharedNavigationViewController presentViewController:mailVC animated:YES completion:nil];
        }
    }

sharedParentViewController and sharedNavigationViewController are defined macros to access root view controller everywhere in the app.

I set up a breakpoint on all exceptions but unfortunately, it never breaks.

With iOS6 and iOS5, everything works fine, any idea of what I can try to fix this?

EDIT:

Here is the crash log:

Stack Trace

Auto Layout still required after executing -layoutSubviews. MFComposeSubjectView's implementation of -layoutSubviews needs to call super.

0   CoreFoundation                      0x3099ff4b <redacted> + 130
1   libobjc.A.dylib                     0x3b1366af objc_exception_throw + 38
2   CoreFoundation                      0x3099fe25 <redacted> + 0
3   Foundation                          0x31347fe3 <redacted> + 90
4   UIKit                               0x33112e63 <redacted> + 538
5   QuartzCore                          0x32d99c6b <redacted> + 142
6   QuartzCore                          0x32d9547b <redacted> + 350
7   QuartzCore                          0x32d9530d <redacted> + 16
8   QuartzCore                          0x32d94d1f <redacted> + 230
9   QuartzCore                          0x32d94b2f <redacted> + 314
10  QuartzCore                          0x32d8e85d <redacted> + 56
11  CoreFoundation                      0x3096b1cd <redacted> + 20
12  CoreFoundation                      0x30968b71 <redacted> + 284
13  CoreFoundation                      0x30968eb3 <redacted> + 730
14  CoreFoundation                      0x308d3c27 CFRunLoopRunSpecific + 522
15  CoreFoundation                      0x308d3a0b CFRunLoopRunInMode + 106
16  GraphicsServices                    0x355c7283 GSEventRunModal + 138
17  UIKit                               0x33177049 UIApplicationMain + 1136
18  teleobs                             0x00037921 main + 116
19  teleobs                             0x000378a8 start + 40
Trifling answered 27/11, 2013 at 7:39 Comment(8)
Are u using appearance selectors to set navigation bar colors ? if u do so, try not to use images to generate colors!Sawhorse
@ChamiraFernando No, I checked right now, UIAppearance selectors are not used at all.Trifling
or u change navigation controller colors using image ? i mean [uicolor colorWithPatternImage] ?Sawhorse
@ChamiraFernando I do not use any pattern image. The only customization performed on navigation controller is this one : self.navigationBar.tintColor = [UIColor whiteColor]; [self.navigationBar setTranslucent:NO];Trifling
its hard to say where it happens.. can u see the whole crash log ?Sawhorse
@ChamiraFernando I have edited my question to show the whole crash log I have.Trifling
let us continue this discussion in chatTrifling
@c0d3Junk13 no solution for the moment, I will get back to this during the day.Trifling
A
0

I guess this issue because of:

  1. Autolayouts is enabled (in Storyboard, etc)
  2. There is UIView category (or more) with calls of - (void)layoutSubviews

Check all UIView categories (in your project) if it calls - (void)layoutSubviews, try to comment this call for testing. Or just turn off autolayouts

Attwood answered 7/2, 2014 at 13:33 Comment(0)
E
0

Maybe because you try to initialize the MFMailComposeViewController with initWithNibName:bundle: instead of init. Try it this way, and it should work.

MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:emailTitle];
[mailComposer setMessageBody:message isHTML:NO];

If it is a problem with your macros you should better first try to call the MFMailComposeViewController the normal way

[self presentViewController:mailComposer animated:YES completion:nil];

without a switch and if it works you can look how to switch it.

Ender answered 7/2, 2014 at 13:54 Comment(1)
A regular init calls [self initWithNibName:nil bundle:nil].Thaddeus
W
0

In my case the issue was I tried to presentViewController: when UIActionSheet still was presented. It has it's own window which overlays ours one. I've added a small delay, 0.1f seconds, and called the presentation of MFMailComposeViewController in dispatch_after block. After that it started to work correctly.

Try to increase delay up to 0.3f if 0.1f doesn't work.

I assume we will have the same problem for UIAlertView and other classes which use those own windows for presentation.

This solution is not elegant so if somebody has a better decision I would be happy to know it.

Willable answered 2/7, 2014 at 10:5 Comment(0)
A
0

in class MFComposeSubjectView,you rewrite -layoutSubviews but not call [super layoutSubviews]

Afore answered 3/6, 2015 at 15:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.