0

我正在尝试复制 Apple“发送邮件”代码,但没有出现电子邮件撰写界面……只是一个空白屏幕。我认为我做对了。没有对故事板做任何事情,因为没有任何动作或出口。没有更改任何一个委托 .h 或 .m 文件。下面是代码。对编码非常陌生。我错过了什么?

.h 文件

#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>

@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>

@end

.m 文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController 

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

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

    [picker setSubject:@"Hello from New Zealand!"];

    // Set up the recipients.
    NSArray *toRecipients = [NSArray arrayWithObjects:@"jfellows123@gmail.com",
                             nil];
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"jfellows123@gmail.com", nil];
    NSArray *bccRecipients = [NSArray arrayWithObjects:@"jfellows123@gmail.com",
                              nil];

    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];
    [picker setBccRecipients:bccRecipients];

    // Attach an image to the email.
    NSString *path = [[NSBundle mainBundle] pathForResource:@"IMG_3639"
                                                     ofType:@"jpg"];
    NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"image/jpg"
                     fileName:@"IMG_3639"];

    // Fill out the email body text.
    NSString *emailBody = @"Beautiful New Zealand!";
    [picker setMessageBody:emailBody isHTML:NO];

    // Present the mail composition interface.
    [self presentViewController:picker animated:YES completion:nil];
}

// The mail compose view controller delegate method
- (void)mailComposeController:(MFMailComposeViewController *)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError *)error
{
    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
4

1 回答 1

1

如果你不介意。您在哪里调用该-(void)displayComposerSheet方法。?

它没有被正确调用。如果是这样,请告诉我您的日志。使用断点。

于 2013-06-13T10:56:46.933 回答