0

我有一个应用程序,在我的 Info-plist 中设置为横向左侧、横向右侧和纵向。但是,我的所有视图控制器通常都在横向模式下运行,并且我已经设置

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

除了视图控制器,我有一个按钮,我想允许用户发送电子邮件。

  - (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 想要旋转到纵向,但似乎不允许这样做。我在控制台中没有看到任何错误消息。在此先感谢您的帮助。

4

2 回答 2

1

我在 iOs 6.0 中发现的一个问题是,如果您在设备上没有任何已配置的邮件,应用程序将会崩溃。只需检查一下

if([MFMailComposeViewController canSendMail])
{
       [self presentViewController:yourMailComposer animated:YES completion:nil];

} 

通过上述检查,我们可以避免崩溃。请注意,我正在使用 iOs 6.1。希望会有所帮助。

于 2013-07-12T11:33:37.210 回答
1

您的应用程序可能内存不足,这是由调用 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

于 2012-04-29T19:39:14.653 回答