iphone - 邮件编辑器在 iPhone 上崩溃

标签 iphone ios autorotate mfmailcomposer

我有一个应用程序,我在我的 Info-plist 中设置了 Landscape Left、Landscape Right 和 Portrait。但是,我的所有 View Controller 通常都在横向模式下运行,并且我已经设置了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}

除了我有一个按钮的 View Controller ,我想让用户发送电子邮件。

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return YES;}

当我尝试发送电子邮件时,我的应用程序崩溃了。它在我的 iPad 上工作得很好。这是我发送电子邮件的代码。

- (IBAction)sendEmail:(id)sender
{
    if ([MFMailComposeViewController canSendMail])
    {
        MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
        mailComposer.mailComposeDelegate = self;

       [mailComposer setSubject:@"HI!"];

        UIImage *myImage = [UIImage imageNamed:@"myPicture.png"];
        NSData *imageData = UIImagePNGRepresentation(myImage);
        [mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"FullTitle.png"];

       NSString *emailBody = @"Hi there!!";
        [mailComposer setMessageBody:emailBody isHTML:NO]; 

        [self presentModalViewController:mailComposer animated:YES];
    }

    else 
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                                                        message:@"Your device does not support email function"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                             otherButtonTitles:nil];
        [alert show];
    }
}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the drafts folder.");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
            break;
        default:
           NSLog(@"Mail not sent.");
             break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

我不确定,但我可能以某种方式将自己锁定在横向模式,所以当我想发送电子邮件时,iPhone 想要旋转到纵向,但似乎不允许这样做。我在控制台中没有看到任何错误消息。 预先感谢您的帮助。

最佳答案

您的应用可能内存不足,这是由调用 UIImagePNGRepresentation() 引起的。此函数在创建 NSData 时将整个图像复制到内存中。图像越大,使用的内存就越多。此问题的可能解决方案是使用 UIImageJPEGRepresentation() 而不是 UIImagePNGRepresentation() 并将类似 0.6 的内容传递给 compressionQuality 参数。可以在 Apple 文档中找到更多信息:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageJPEGRepresentation

关于iphone - 邮件编辑器在 iPhone 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10373507/

相关文章:

iphone - 如何将我的 iphone 应用程序与 twitter api 集成?

ios - 具有全屏 ImageView 的启动屏幕 .XIB

ios - 如何避免 iOS OpenGL ES 应用程序自动旋转时的瞬间拉伸(stretch)

php - 无法读取 POST 参数

Android:自动旋转在 setRequestedOrientation 后不起作用

iphone - 在 iPhone 上横向全屏播放 YouTube,纵向内嵌播放 YouTube

iphone - 带有iPhone上的NSTimers的“Multi-threading”

iphone - 核心数据中的拒绝规则无法正常工作

ios - 即使在 viewDidLoad 中设置了委托(delegate),UISearchBar 也无法正常工作

ios - 如何在快速启动时加载详细 View Controller (从 Split View)?