我试图复制Apple“发送邮件消息”代码,但电子邮件撰写界面没有出现..只是一个空白屏幕。我想我做对了。没有对 Storyboard做任何事情,因为没有任何 Action 或导出。未更改委托(delegate) .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
最佳答案
如果你不介意的话。您调用 -(void)displayComposerSheet
方法的位置。 ?
它没有被正确调用。如果是这样,请让我知道您的日志。使用断点。
关于iphone - 没有出现邮件撰写界面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17085241/