【问题标题】:MFMailComposeViewController loads a blank white screenMFMailComposeViewController 加载一个空白的白屏
【发布时间】:2011-04-26 02:05:29
【问题描述】:

我正在运行 OS 3.1.3 的 iPod Touch 上进行测试

试图让用户从应用程序内发送电子邮件 - 但是当执行以下代码时,整个屏幕变成完全空白/白色。

关于为什么会发生这种情况的任何想法? 我在项目中有 MessageUI 框架。 我在头文件中导入和委托:

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
<MFMailComposeViewControllerDelegate>

这是代码,非常标准:

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"App Feedback"];
    [picker setToRecipients:[NSArray arrayWithObject:@"xyz@gmail.com"]];

    [self presentModalViewController:picker animated:YES];
    [picker release];
    }

然后我有 didFinishWithResult 函数,它会在发送电子邮件时关闭 ModalViewController。

但同样,我得到的只是 iPod Touch 上的空白屏幕。 =/

谢谢!

【问题讨论】:

  • 您为什么使用名称picker 作为邮件控制器?
  • 您可以使用任何您想要的名称 - 您正在创建一个新的 MFMailComposeViewController 并将其命名为 *picker 或 *picklesAndCheese 或任何您想要的名称
  • 哇这个问题已经三年多了。我不再有撰写电子邮件的问题了,但我也不再对 iOS 3.1.3 做任何事情... =)
  • @RansLearns 当然,但最好将对象命名为与其所属的类相关的名称。例如,mailComposeController 或类似的东西。 Apple 的所有示例代码都使用来自UIViewController 的对象执行此操作。这就是我的意思,显然你可以随心所欲地命名它!
  • 明白了。老实说,当我第一次学习从应用程序中发送电子邮件时,我相信我是从 stackoverflow 中得到它的,并且从那以后的所有年里都不必更改它。在这里似乎很常见:stackoverflow.com/questions/7706673/…stackoverflow.com/questions/6934470/…

标签: iphone email ipod-touch


【解决方案1】:
if([MFMailComposeViewController canSendMail]){

        MFMailComposeViewController *mail=[[MFMailComposeViewController alloc]init];
        mail.mailComposeDelegate=self;
        [mail setSubject:@"App Feedback"];          
        [mail setMessageBody:@"*your message  content*" isHTML:NO];
        [self presentModalViewController:mail animated:YES];
        [mail release];         
    }

- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
        [self dismissModalViewControllerAnimated:YES];

}

【讨论】:

    【解决方案2】:

    您可以查看来自苹果的示例代码: http://developer.apple.com/library/ios/#samplecode/MessageComposer/Listings/Classes_MessageComposerViewController_m.html

    -(IBAction)showMailPicker:(id)sender {

    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    
    if (mailClass != nil) {
            [self displayMailComposerSheet];
    
        if ([mailClass canSendMail]) {
            [self displayMailComposerSheet];
        }
        else {
            feedbackMsg.hidden = NO;
            feedbackMsg.text = @"Device not configured to send mail.";
        }
    }
    else    {
        feedbackMsg.hidden = NO;
        feedbackMsg.text = @"Device not configured to send mail.";
    }
    

    }

    -(void)displayMailComposerSheet { MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self;

    [picker setSubject:@"Hello from California!"];
    
    
    
    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 
    
    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];  
    [picker setBccRecipients:bccRecipients];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"];
    
    
    NSString *emailBody = @"It is raining in sunny California!";
    [picker setMessageBody:emailBody isHTML:NO];
    
    [self presentModalViewController:picker animated:YES];
    [picker release];
    

    } - (void)mailComposeController:(MFMailComposeViewController*)控制器 didFinishWithResult:(MFMailComposeResult)结果错误:(NSError*)error {

    feedbackMsg.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            feedbackMsg.text = @"Result: Mail sending canceled";
            break;
        case MFMailComposeResultSaved:
            feedbackMsg.text = @"Result: Mail saved";
            break;
        case MFMailComposeResultSent:
            feedbackMsg.text = @"Result: Mail sent";
            break;
        case MFMailComposeResultFailed:
            feedbackMsg.text = @"Result: Mail sending failed";
            break;
        default:
            feedbackMsg.text = @"Result: Mail not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
    

    }

    【讨论】:

      猜你喜欢
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 2021-04-26
      • 1970-01-01
      • 2015-05-02
      • 2016-07-05
      相关资源
      最近更新 更多