MFMailComposeViewController加载一个空白的白色屏幕

时间:2011-04-26 02:05:29

标签: iphone email ipod-touch

我正在测试运行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上的空白屏幕。 = /

谢谢!

2 个答案:

答案 0 :(得分:0)

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];

}

答案 1 :(得分:0)

您可以查看来自apple的示例代码: 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.";
}

}

- (无效)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 *)错误{

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];

}

相关问题