Composing mail in iOS 7: assertion fails in - [MFComposeSubjectView layoutSublayersOfLayer:]

I am currently having problems with iOS7 and MFMailComposeViewController . Sometimes (not often, but not always) I have the following failure when presenting MFMailComposeViewController :

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

This is how I represent 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 defined macros to access the root view controller in the application.

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

Everything works fine with iOS6 and iOS5, any idea that I can try to fix this?

EDIT:

Here is the crash log:

 Stack Trace Auto Layout still required after executing -layoutSubviews. MFComposeSubjectView 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 
+6
source share
4 answers

I think this problem is due to:

  • Autolocation enabled (in storyboard, etc.)
  • There is a UIView category (or more) with calls - (void)layoutSubviews

Check all the UIView categories (in your project), if it calls - (void)layoutSubviews , try commenting out this call for testing. Or just turn off the self-timer

0
source

Perhaps because you are trying to initialize 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 this is a problem with your macros , it is best to try calling the MFMailComposeViewController normal path first

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

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

0
source

In my case, the problem was that I tried presentViewController: when the UIActionSheet was still present. He has his own window, which is superimposed on ours. I added a slight delay of 0.1f seconds and 0.1f presentation of MFMailComposeViewController in the dispatch_after block. After that, he began to work correctly.

Try increasing the delay to 0.3f if 0.1f does not work.

I assume that we will have the same problem for UIAlertView and other classes that use these native windows for presentation.

This solution is not elegant, therefore, if someone has a better solution, I would be glad to know it.

0
source

in the MFComposeSubjectView class, you rewrite - layoutSubviews but don't call [super layoutSubviews]

0
source

Source: https://habr.com/ru/post/958905/


All Articles