iphone - 没有出现邮件撰写界面?

标签 iphone ios

我试图复制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/

相关文章:

ios - 如何在这个 block 中强烈修复 "Capturing ' block '很可能导致保留循环'

ios - 在 iOS 7 上选择后 UITableViewCell 不更新

javascript - Google map Javascript API 无法在 IOS 设备上运行

iphone - 将 NSMutableURLRequest 超时设置为自定义时间

iOS:当应用程序因任何崩溃而退出时是否有任何委托(delegate)方法

ios - 屏蔽 UIView

ios - 分配位置后SKSpriteNode变为null

iphone - 在 Windows 上编译和签署 xcode 项目

iphone - 如何在应用程序中使用 iPhone 铃声

ios - 在 xCode 中动态调试变量?