2011-04-26 66 views
0

我在iPod的触控测试运行OS 3.1.3MFMailComposeViewController加载一个空白屏幕

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

为什么会发生这种情况的任何想法? 我已经获得了项目中的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:@"[email protected]"]]; 

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

然后,我有didFinishWithResult功能,将驳回ModalViewController当电子邮件有已经送走了。

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

谢谢!

+0

你为什么要使用邮件控制器的名称为“picker”? – 2015-01-06 10:01:22

+0

你可以使用任何你想要的名字 - 你正在创建一个新的MFMailComposeViewController并命名它* picker或* picklesAndCheese或任何你想要的 – RanLearns 2015-01-07 18:51:45

+0

哇这个问题已经超过三年了。我再也没有编写电子邮件的问题,但我也没有做任何事情与iOS 3.1.3了...... =) – RanLearns 2015-01-07 18:52:42

回答

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

} 
0

你可以看一下示例代码苹果: http://developer.apple.com/library/ios/#samplecode/MessageComposer/Listings/Classes_MessageComposerViewController_m.html

- (IBAction为)showMailPicker:(ID)发送{

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:@"[email protected]"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

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

} - (空)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]; 

}