MFMailComposeViewController 崩溃
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Support Enquiry"];
[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
我的代码崩溃了
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
:
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry',
reason: 'CALayer position contains NaN: [nan 24.5]'
*** Call stack at first throw:
(
0 CoreFoundation 0x011f75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0134b313 objc_exception_throw + 44
2 CoreFoundation 0x011afef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x011afe6a +[NSException raise:format:] + 58
4 QuartzCore 0x00145ba2 _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 177
5 QuartzCore 0x00145d55 -[CALayer setPosition:] + 42
6 QuartzCore 0x0013e24d -[CALayer setFrame:] + 763
7 UIKit 0x0047eda2 -[UIView(Geometry) setFrame:] + 255
8 UIKit 0x004ea660 -[UITextField setFrame:] + 166
9 MessageUI 0x001faa48 -[_MFComposeRecipientView reflow] + 3371
10 MessageUI 0x001f9678 -[_MFComposeRecipientView setLabel:] + 79
11 MessageUI 0x001ff144 -[MFMailComposeView _setupField:withLabel:navTitle:property:changingView:toSize:fieldFrame:visible:] + 234
12 MessageUI 0x00203277 -[MFMailComposeView _layoutSubviews:changingView:toSize:searchResultsWereDismissed:] + 1768
13 MessageUI 0x001fea6f -[MFMailComposeView _layoutSubviews:changingView:toSize:] + 71
14 MessageUI 0x001fea22 -[MFMailComposeView _layoutSubviews:] + 69
15 MessageUI 0x00200859 -[MFMailComposeView initWithFrame:navigationItem:options:delegate:] + 2175
16 MessageUI 0x00215ea6 -[MFMailComposeController initializeUI] + 228
17 MessageUI 0x0021cfb9 -[MFMailComposeController initForContentSize:navigationItem:options:] + 147
18 MessageUI 0x00236267 -[MFMailComposeRootViewController initWithCompositionContext:contentSize:mailComposeControllerOptions:] + 377
19 MessageUI 0x0022fbe7 -[MFMailComposeViewController initWithComposition:contentSize:mailComposeControllerOptions:] + 726
20 MessageUI 0x0022f634 -[MFMailComposeViewController initWithComposition:] + 68
21 MessageUI 0x0022f71e -[MFMailComposeViewController initWithNibName:bundle:] + 98
...
知道发生了什么吗?
编辑:到目前为止,所有答案都没有做任何事情,它仍然崩溃:(
编辑2:我终于找到了问题 - 我在文本字段中添加了一个类别,而 MFMailComposeViewController 根本不喜欢这样。
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@"Support Enquiry"];
[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
My code crashes on the
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
line with:
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry',
reason: 'CALayer position contains NaN: [nan 24.5]'
*** Call stack at first throw:
(
0 CoreFoundation 0x011f75a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x0134b313 objc_exception_throw + 44
2 CoreFoundation 0x011afef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x011afe6a +[NSException raise:format:] + 58
4 QuartzCore 0x00145ba2 _ZL18CALayerSetPositionP7CALayerRKN2CA4Vec2IdEEb + 177
5 QuartzCore 0x00145d55 -[CALayer setPosition:] + 42
6 QuartzCore 0x0013e24d -[CALayer setFrame:] + 763
7 UIKit 0x0047eda2 -[UIView(Geometry) setFrame:] + 255
8 UIKit 0x004ea660 -[UITextField setFrame:] + 166
9 MessageUI 0x001faa48 -[_MFComposeRecipientView reflow] + 3371
10 MessageUI 0x001f9678 -[_MFComposeRecipientView setLabel:] + 79
11 MessageUI 0x001ff144 -[MFMailComposeView _setupField:withLabel:navTitle:property:changingView:toSize:fieldFrame:visible:] + 234
12 MessageUI 0x00203277 -[MFMailComposeView _layoutSubviews:changingView:toSize:searchResultsWereDismissed:] + 1768
13 MessageUI 0x001fea6f -[MFMailComposeView _layoutSubviews:changingView:toSize:] + 71
14 MessageUI 0x001fea22 -[MFMailComposeView _layoutSubviews:] + 69
15 MessageUI 0x00200859 -[MFMailComposeView initWithFrame:navigationItem:options:delegate:] + 2175
16 MessageUI 0x00215ea6 -[MFMailComposeController initializeUI] + 228
17 MessageUI 0x0021cfb9 -[MFMailComposeController initForContentSize:navigationItem:options:] + 147
18 MessageUI 0x00236267 -[MFMailComposeRootViewController initWithCompositionContext:contentSize:mailComposeControllerOptions:] + 377
19 MessageUI 0x0022fbe7 -[MFMailComposeViewController initWithComposition:contentSize:mailComposeControllerOptions:] + 726
20 MessageUI 0x0022f634 -[MFMailComposeViewController initWithComposition:] + 68
21 MessageUI 0x0022f71e -[MFMailComposeViewController initWithNibName:bundle:] + 98
...
Any idea whats going on?
EDIT: All the answer so far have done nothing, it still crashes :(
EDIT 2: I finally figured out the problem - I had added a category to text field and MFMailComposeViewController did not like that at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
正如提问者报告的问题一样,
MFMailComposeViewController
使用了一些不应分类的本机元素。因此,您必须确保UITextField
或UITextView
等元素上没有任何类别。As the asker reported on his question,
MFMailComposeViewController
uses some native elements that shouldn't be categorized. So, you have to be sure there aren't any categories on elements likeUITextField
orUITextView
.我觉得您对 iOS
MFMailComposeViewController
类的To:
字段有问题。可能是,您正在发送 “To Recipient” 字符串数组,该数组没有有效的
NSString
对象,并且在内部 iOS 尝试使用To:
字段的sizeWithFont
计算字符串的高度。只是建议您通过替换以下语句来测试上述假设。
。
如果它再次崩溃并显示相同的消息,请告诉我
编辑:
UITableView 崩溃给出“CALayerInvalidGeometry”,原因:'CALayer位置包含NaN:[160 nan]'
It seems me you have issue with the
To:
field of iOSMFMailComposeViewController
class.May be,you are sending the "To Recipient" string array, which doesn't have the valid
NSString
object, and internally iOS try to calculate the height of your string usingsizeWithFont
forTo:
field .Just suggest you to test the above assumption by replacing the below statement.
With
Let me know if it again crash with same message .
EDITED:
UITableView crash gives 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [160 nan]'
只需尝试使用
[mailViewController setToRecipients:[NSArray arrayWithObjects:EMAIL_SUPPORT,nil]];
请参阅此链接:
http://www. edumobile.org/iphone/iphone-programming-tutorials/mailsend-in-the-iphone/
Just try using
[mailViewController setToRecipients:[NSArray arrayWithObjects:EMAIL_SUPPORT,nil]];
either refer to this link:
http://www.edumobile.org/iphone/iphone-programming-tutorials/mailsend-in-the-iphone/
这是我将调试设置为 max 时得到的结果:
bool _WebTryThreadLock(bool), 0x4be8910: 尝试从主线程或 Web 线程以外的线程获取 Web 锁。这可能是从辅助线程调用 UIKit 的结果。现在崩溃了......
但堆栈跟踪略有不同:
this is what I got with debugging set to max:
bool _WebTryThreadLock(bool), 0x4be8910: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
slightly different stacktrace though:
除了主线程之外,您不得从任何线程访问 UI。曾经。
所以这对我的情况确实有帮助:
You must not access UI from any thread besides the main thread. Ever.
So this indeed helped in my case:
如果没有任何帮助,您可以随时打开 mailto url:
if nothing helps you can always open a mailto url:
MFMailComposeViewController 是 UINavigationController 的子类,因此请确保此处的“self”具有 UINavigationController。
确保您已导入 MessegeUI 框架。
检查您是否已在类的 .h 文件中确认 UINavigationController 协议。
请告诉我这是否解决了问题。
谢谢!
伊尚克
MFMailComposeViewController is a subclass of a UINavigationController, so make sure that "self" here has a UINavigationController.
Make sure that you have imported the MessegeUI framewok.
Check that you have confirmed to UINavigationController protocol in the .h file of the class.
Please, let me know if that solves the issue.
Thanks!
Ishank
如果您将以下类别添加到文本字段,那么 MFMailComposeViewController 根本不喜欢这样。所以要避免这种情况。
我不知道为什么。我正在写我所观察到的事情。
但是您可以添加这些类别来自定义您的文本字段:
我认为这会对您有所帮助。
If you added the below category to text field then MFMailComposeViewController did not like that at all. So avoid that.
I don't know why. I am writing what I observed.
But You can add these categories to customize your text field:
I think this will help you.
在使用 ARC 在 iOS5/6 上呈现视图控制器时,我遇到了同样的问题。
我的解决方案是保留使用 ivar 呈现 MFMailComposeViewController 的对象。
I've had the same issue when presenting the view controller on iOS5/6 with ARC.
My solution was to retain the object that was presenting the MFMailComposeViewController with an ivar.