Reputation: 45
I'm trying to replicates Apple "Sending a Mail Message" code, but the email composition interface doen't appear.. just a blank screen. I think I did this right. Didn't do anything with the storyboard since there aren't any actions or outlets. Didn't change either of the delegate .h or .m files. Below is the code. Very new to coding. What have I missed?
.h file
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController <MFMailComposeViewControllerDelegate>
@end
.m file
#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
Upvotes: 0
Views: 121
Reputation: 15335
If you don't mind . Where you are calling the -(void)displayComposerSheet
method. ?
It doesn't get called right . If so Let me know your log . Use breakPoints .
Upvotes: 1