我試圖複製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:@"[email protected]",
nil];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObjects:@"[email protected]",
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
你在哪裏調用這個'displayComposerSheet'? –
你需要打電話給你的方法來顯示mailcomposer .. – samfisher