MFMailComposeViewController 加载空白屏幕

发布于 2024-11-03 07:59:24 字数 984 浏览 0 评论 0原文

我正在运行 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:@"[email protected]"]];

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

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

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

谢谢!

I'm testing on an iPod Touch running OS 3.1.3

Trying to allow users to send an email from within the app - but when the following code is executed, the entire screen just turns completely blank / white.

Any ideas on why this is happening?
I've got the MessageUI framework in the project.
I'm importing and delegating in the header file:

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

And here's the code, pretty standard:

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

And then I have the didFinishWithResult function that would dismiss the ModalViewController when the email has been sent.

But again, all I get is a blank white screen on my iPod Touch. =/

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花开柳相依 2024-11-10 07:59:24
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];

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

}
虫児飞 2024-11-10 07:59:24

你可以看一下苹果的示例代码:
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 = 自我;

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

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

}

You can take look at sample code from 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.";
}

}

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

}
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(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];

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文