2011-04-26 98 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]; 

}