MFMailComposeViewController 崩溃

发布于 2024-11-14 22:55:35 字数 3308 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

旧时光的容颜 2024-11-21 22:55:35

正如提问者报告的问题一样,MFMailComposeViewController 使用了一些不应分类的本机元素。因此,您必须确保 UITextFieldUITextView 等元素上没有任何类别。

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 like UITextField or UITextView.

放手` 2024-11-21 22:55:35

我觉得您对 iOS MFMailComposeViewController 类的 To: 字段有问题。
可能是,您正在发送 “To Recipient” 字符串数组,该数组没有有效的 NSString 对象,并且在内部 iOS 尝试使用 To: 字段的 sizeWithFont 计算字符串的高度。

只是建议您通过替换以下语句来测试上述假设。

[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];

[mailViewController setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];

如果它再次崩溃并显示相同的消息,请告诉我

编辑:

UITableView 崩溃给出“CALayerInvalidGeometry”,原因:'CALayer位置包含NaN:[160 nan]'

It seems me you have issue with the To: field of iOS MFMailComposeViewController 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 using sizeWithFont for To: field .

Just suggest you to test the above assumption by replacing the below statement.

[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];

With

[mailViewController setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];

Let me know if it again crash with same message .

EDITED:

UITableView crash gives 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [160 nan]'

还不是爱你 2024-11-21 22:55:35

只需尝试使用

[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/

累赘 2024-11-21 22:55:35

这是我将调试设置为 max 时得到的结果:

bool _WebTryThreadLock(bool), 0x4be8910: 尝试从主线程或 Web 线程以外的线程获取 Web 锁。这可能是从辅助线程调用 UIKit 的结果。现在崩溃了......

但堆栈跟踪略有不同:

#2  0x32b69f40 in -[MFComposeBodyField initWithFrame:]
#3  0x32b69afe in -[MFMailComposeView _setupBodyFieldWithHeaderFrame:enclosingFrame:changingView:frameToPin:wasSearching:]
#4  0x32b66c12 in -[MFMailComposeView _layoutSubviews:changingView:toSize:searchResultsWereDismissed:]
#5  0x32b6651e in -[MFMailComposeView _layoutSubviews:changingView:toSize:]
#6  0x001cafe2 in -[MFMailComposeViewAccessibility(SafeCategory) _layoutSubviews:changingView:toSize:]
#7  0x32b664ee in -[MFMailComposeView _layoutSubviews:]
#8  0x32b66202 in -[MFMailComposeView initWithFrame:navigationItem:options:delegate:]
#9  0x32b65876 in -[MFMailComposeController initializeUI]
#10 0x32b656c0 in -[MFMailComposeController initForContentSize:navigationItem:options:]
#11 0x32b6558c in -[MFMailComposeRootViewController initWithCompositionContext:contentSize:mailComposeControllerOptions:]
#12 0x32b64dc2 in -[MFMailComposeViewController initWithComposition:contentSize:mailComposeControllerOptions:]
#13 0x32b64bfe in -[MFMailComposeViewController initWithComposition:]
#14 0x32b8cfb2 in -[MFMailComposeViewController initWithNibName:bundle:]
#15 0x33169a12 in -[UIViewController init]

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:

#2  0x32b69f40 in -[MFComposeBodyField initWithFrame:]
#3  0x32b69afe in -[MFMailComposeView _setupBodyFieldWithHeaderFrame:enclosingFrame:changingView:frameToPin:wasSearching:]
#4  0x32b66c12 in -[MFMailComposeView _layoutSubviews:changingView:toSize:searchResultsWereDismissed:]
#5  0x32b6651e in -[MFMailComposeView _layoutSubviews:changingView:toSize:]
#6  0x001cafe2 in -[MFMailComposeViewAccessibility(SafeCategory) _layoutSubviews:changingView:toSize:]
#7  0x32b664ee in -[MFMailComposeView _layoutSubviews:]
#8  0x32b66202 in -[MFMailComposeView initWithFrame:navigationItem:options:delegate:]
#9  0x32b65876 in -[MFMailComposeController initializeUI]
#10 0x32b656c0 in -[MFMailComposeController initForContentSize:navigationItem:options:]
#11 0x32b6558c in -[MFMailComposeRootViewController initWithCompositionContext:contentSize:mailComposeControllerOptions:]
#12 0x32b64dc2 in -[MFMailComposeViewController initWithComposition:contentSize:mailComposeControllerOptions:]
#13 0x32b64bfe in -[MFMailComposeViewController initWithComposition:]
#14 0x32b8cfb2 in -[MFMailComposeViewController initWithNibName:bundle:]
#15 0x33169a12 in -[UIViewController init]
沙与沫 2024-11-21 22:55:35

除了主线程之外,您不得从任何线程访问 UI。曾经。

所以这对我的情况确实有帮助:

dispatch_async(dispatch_get_main_queue(), ^{
    /* Do somthing here with UIKit here */  

MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] initWithRootViewController:view] autorelease];
picker.mailComposeDelegate = self;  
NSArray *toRecipients = [NSArray arrayWithObject: subject ];    
[picker setToRecipients:to];    
[view presentModalViewController:picker animated:YES];
});

You must not access UI from any thread besides the main thread. Ever.

So this indeed helped in my case:

dispatch_async(dispatch_get_main_queue(), ^{
    /* Do somthing here with UIKit here */  

MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] initWithRootViewController:view] autorelease];
picker.mailComposeDelegate = self;  
NSArray *toRecipients = [NSArray arrayWithObject: subject ];    
[picker setToRecipients:to];    
[view presentModalViewController:picker animated:YES];
});
爱情眠于流年 2024-11-21 22:55:35

如果没有任何帮助,您可以随时打开 mailto url:

body= [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)body, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];
String uri= [@"mailto:" adds:to];
uri=[[uri adds:@"?subject="] adds:subject];
uri=[[uri adds:@"&body="] adds:body];

if nothing helps you can always open a mailto url:

body= [(NSString*)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)body, NULL, CFSTR("?=&+"), kCFStringEncodingUTF8) autorelease];
String uri= [@"mailto:" adds:to];
uri=[[uri adds:@"?subject="] adds:subject];
uri=[[uri adds:@"&body="] adds:body];
一念一轮回 2024-11-21 22:55:35
  1. MFMailComposeViewController 是 UINavigationController 的子类,因此请确保此处的“self”具有 UINavigationController。

  2. 确保您已导入 MessegeUI 框架。

  3. 检查您是否已在类的 .h 文件中确认 UINavigationController 协议。

请告诉我这是否解决了问题。

谢谢!

伊尚克

  1. MFMailComposeViewController is a subclass of a UINavigationController, so make sure that "self" here has a UINavigationController.

  2. Make sure that you have imported the MessegeUI framewok.

  3. 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

我的鱼塘能养鲲 2024-11-21 22:55:35

如果您将以下类别添加到文本字段,那么 MFMailComposeViewController 根本不喜欢这样。所以要避免这种情况。
我不知道为什么。我正在写我所观察到的事情。

 - (CGRect)textRectForBounds:(CGRect)bounds {

          return CGRectInset( bounds , 10 , 0 );
    }

但是您可以添加这些类别来自定义您的文本字段:

      - (CGRect)borderRectForBounds:(CGRect)bounds;
      - (CGRect)placeholderRectForBounds:(CGRect)bounds;
      - (CGRect)editingRectForBounds:(CGRect)bounds;
      - (CGRect)clearButtonRectForBounds:(CGRect)bounds;
      - (CGRect)leftViewRectForBounds:(CGRect)bounds;
      - (CGRect)rightViewRectForBounds:(CGRect)bounds;

我认为这会对您有所帮助。

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.

 - (CGRect)textRectForBounds:(CGRect)bounds {

          return CGRectInset( bounds , 10 , 0 );
    }

But You can add these categories to customize your text field:

      - (CGRect)borderRectForBounds:(CGRect)bounds;
      - (CGRect)placeholderRectForBounds:(CGRect)bounds;
      - (CGRect)editingRectForBounds:(CGRect)bounds;
      - (CGRect)clearButtonRectForBounds:(CGRect)bounds;
      - (CGRect)leftViewRectForBounds:(CGRect)bounds;
      - (CGRect)rightViewRectForBounds:(CGRect)bounds;

I think this will help you.

想你的星星会说话 2024-11-21 22:55:35

在使用 ARC 在 iOS5/6 上呈现视图控制器时,我遇到了同样的问题。
我的解决方案是保留使用 ivar 呈现 MFMailComposeViewController 的对象。

@interface MyClass (){
     MailUtils *_mailUtils;
}
@end


{...
_mailUtils = [[MailUtils alloc] init];
[_mailUtils publish]; //in this method I create the 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.

@interface MyClass (){
     MailUtils *_mailUtils;
}
@end


{...
_mailUtils = [[MailUtils alloc] init];
[_mailUtils publish]; //in this method I create the MFMailComposeViewController
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文