我使用邮件编辑器发送邮件的应用程序之一,但不幸的是,当我点击发送,保存或取消邮件然后应用程序崩溃。 甚至应用程序仅支持纵向模式,并且未实现任何更改方向的代码。 Mail Composer方法代码: -
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
[mailViewController setMailComposeDelegate:self];
[mailViewController setToRecipients:[NSArray arrayWithObject:MAIL_EMAIL]];
[mailViewController setSubject:MAIL_SUBJECT];
[mailViewController setMessageBody:MAIL_MESSAGE isHTML:NO];
[self presentViewController:mailViewController animated:YES completion:^{
}];
Mail Composer委派方法: -
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:^ {
}];
**Error** :-
*** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
*** First throw call stack:
(
0 CoreFoundation 0x0306d1e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x02dec8e5 objc_exception_throw + 44
2 CoreFoundation 0x0306cfbb +[NSException raise:format:] + 139
3 UIKit 0x01bdb3ec -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 580
4 UIKit 0x01e793d5 -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2330
5 UIKit 0x01bd8bda -[UIViewController _dismissViewControllerWithTransition:from:completion:] + 1647
6 UIKit 0x01bd852e -[UIViewController dismissViewControllerWithTransition:completion:] + 1281
7 UIKit 0x01bd852e -[UIViewController dismissViewControllerWithTransition:completion:] + 1281
8 UIKit 0x01bd9729 -[UIViewController dismissViewControllerAnimated:completion:] + 57
9 TestApp 0x0004c794 -[HelpViewController mailComposeController:didFinishWithResult:error:] + 340
10 MessageUI 0x019ba012 -[MFMailComposeInternalViewController _notifyCompositionDidFinish] + 535
11 MessageUI 0x019b9d98 -[MFMailComposeInternalViewController compositionFinishedWithResult:error:] + 210
12 MessageUI 0x019bbc5d -[MFMailComposeRemoteViewController serviceCompositionFinishedWithResult:error:] + 84
13 CoreFoundation 0x0306191d __invoking___ + 29
14 CoreFoundation 0x0306182a -[NSInvocation invoke] + 362
15 UIKit 0x020d5f0f __63-[_UIViewServiceInterface connection:handleInvocation:isReply:]_block_invoke + 36
16 libdispatch.dylib 0x0336c7b8 _dispatch_call_block_and_release + 15
17 libdispatch.dylib 0x033814d0 _dispatch_client_callout + 14
18 libdispatch.dylib 0x0336f726 _dispatch_main_queue_callback_4CF + 340
19 CoreFoundation 0x030d243e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
20 CoreFoundation 0x030135cb __CFRunLoopRun + 1963
21 CoreFoundation 0x030129d3 CFRunLoopRunSpecific + 467
22 CoreFoundation 0x030127eb CFRunLoopRunInMode + 123
23 GraphicsServices 0x040055ee GSEventRunModal + 192
24 GraphicsServices 0x0400542b GSEventRun + 104
25 UIKit 0x01aacf9b UIApplicationMain + 1225
26 TestApp 0x0001e30d main + 141
27 libdyld.dylib 0x035b670d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
答案 0 :(得分:0)
将以下代码添加到您的UIViewController子类(您用来呈现邮件编辑器的子类)
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
-(BOOL)shouldAutorotate
{
return NO;
}