簡體   English   中英

Mail Composer在iPhone上崩潰

[英]Mail Composer crashes on iPhone

我有一個應用程序,我在Info-plist中設置為Landscape Left,Landscape Right和Portrait。 但是,我通常在所有視圖控制器的橫向模式下操作,並且我已設置

- (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想要旋轉到肖像,但似乎是不允許的。 我在控制台中沒有看到任何錯誤消息。 在此先感謝您的幫助。

您的應用程序可能內存不足,這是由調用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

我在iOs 6.0中發現的一個問題是,如果您在設備上沒有任何已配置的郵件,應用程序將崩潰。 只需檢查一下

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

} 

通過以上檢查,我們可以避免崩潰。請注意我正在研究iOs 6.1。 希望會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM