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根本不喜欢该类别。     
已邀请:
        正如问问者在他的问题上的报道一样,“ 3”使用了一些本不应分类的本机元素。因此,您必须确保元素
UITextField
或ѭ5are中没有任何类别。     
        看来我对iOS
MFMailComposeViewController
类的
To:
字段有疑问。 可能是,您正在发送\“ To Recipient \”字符串数组,其中没有有效的
NSString
对象,iOS内部在internal6 try字段中尝试使用try9ѭ计算字符串的高度。 只是建议您通过替换以下语句来测试上述假设。
[mailViewController setToRecipients:[NSArray arrayWithObject:EMAIL_SUPPORT]];
[mailViewController setToRecipients:[NSArray arrayWithObject:@\"myCompanySupport@abc.com\"]];
让我知道它是否再次因相同的消息而崩溃。 编辑: UITableView崩溃给出了“ CALayerInvalidGeometry”,原因:“ CALayer位置包含NaN:[160 nan]”     
        只需尝试使用 [mailViewController setToRecipients:[NSArray arrayWithObjects:EMAIL_SUPPORT,nil]]; 请参考以下链接: http://www.edumobile.org/iphone/iphone-programming-tutorials/mailsend-in-the-iphone/     
        这是我将调试设置为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]
    
        您不得从主线程以外的任何线程访问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];
});
    
        如果没有帮助,您可以随时打开mailto网址:
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];
    
         MFMailComposeViewController是UINavigationController的子类,因此请确保此处的“ self”具有UINavigationController。 确保已导入MessegeUI framewok。 检查是否已在该类的.h文件中确认使用UINavigationController协议。 请让我知道是否可以解决问题。 谢谢! 伊尚克     
        如果将以下类别添加到文本字段,则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;
我认为这会对您有所帮助。     
        在具有ARC的iOS5 / 6上呈现视图控制器时,我遇到了相同的问题。 我的解决方案是保留使用ivar呈现MFMailComposeViewController的对象。
@interface MyClass (){
     MailUtils *_mailUtils;
}
@end


{...
_mailUtils = [[MailUtils alloc] init];
[_mailUtils publish]; //in this method I create the MFMailComposeViewController
}
    

要回复问题请先登录注册