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根本不喜欢它。
答案 0 :(得分:1)
我觉得你对iOS To:
类的MFMailComposeViewController
字段有疑问。
可能是,您发送“收件人”字符串数组,该数组没有有效的NSString
对象,而内部 iOS 尝试计算高度sizeWithFont
字段使用To:
的字符串。
建议您通过替换以下声明来测试上述假设。
[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];
使用
[mailViewController setToRecipients:[NSArray arrayWithObject:@"myCompanySupport@abc.com"]];
让我知道它是否会再次崩溃同样的消息。
<强>编辑:强>
UITableView crash gives 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [160 nan]'
答案 1 :(得分:1)
当提问者报告他的问题时,MFMailComposeViewController
使用了一些不应归类的原生元素。因此,您必须确保UITextField
或UITextView
等元素上没有任何类别。
答案 2 :(得分:0)
尝试使用
[mailViewController setToRecipients:[NSArray arrayWithObjects:EMAIL_SUPPORT,nil]];
请参阅此链接:
http://www.edumobile.org/iphone/iphone-programming-tutorials/mailsend-in-the-iphone/
答案 3 :(得分:0)
这是调试设置为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]
答案 4 :(得分:0)
除了主线程之外,您不能从任何线程访问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];
});
答案 5 :(得分:0)
如果没有任何帮助,您可以随时打开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];
答案 6 :(得分:0)
MFMailComposeViewController是UINavigationController的子类,因此请确保此处的“self”具有UINavigationController。
确保您已导入MessegeUI framewok。
检查您是否在类的.h文件中确认了UINavigationController协议。
如果能解决问题,请告诉我。
谢谢!
Ishank
答案 7 :(得分:0)
如果您将以下类别添加到文本字段,那么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;
我认为这会对你有帮助。
答案 8 :(得分:0)
在使用ARC在iOS5 / 6上呈现视图控制器时,我遇到了同样的问题。 我的解决方案是保留使用ivar呈现MFMailComposeViewController的对象。
@interface MyClass (){
MailUtils *_mailUtils;
}
@end
{...
_mailUtils = [[MailUtils alloc] init];
[_mailUtils publish]; //in this method I create the MFMailComposeViewController
}