Mail Composition Interface Doesn't Appear? - iphone

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:#"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

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 .

Related

iPhone SDK record video then email it

I was wondering if someone could show me how to record video and add it as attachment to mail composer in IOS. The more specific the better. Thanks.
.h file
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
UIImagePickerController *imagePicker;
NSURL *videoURL;
}
-(IBAction)submitVideo;
.m file
- (void)viewDidLoad
{
[super viewDidLoad];
//set image picker
imagePicker = [[UIImagePickerController alloc]init];
NSArray *mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
imagePicker.mediaTypes = [mediaTypes filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"(SELF contains %#)", #"movie"]];
imagePicker.delegate = self;
imagePicker.videoMaximumDuration = 60.0;
imagePicker.allowsEditing = YES;
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
-(IBAction)submitVideo
{
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
NSLog(#"movie captured %#", info);
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(sendMail) userInfo:nil repeats:NO];
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)sendMail
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail addAttachmentData:[NSData dataWithContentsOfURL:videoURL] mimeType:#"video/MOV" fileName:#"Video.MOV"];
[mail setSubject:#"video"];
[mail setMessageBody:#"body" isHTML:YES];
[mail setToRecipients:[NSArray arrayWithObject:#"myemail#jhd.com"]];
[self presentViewController:mail animated:YES completion:nil];
}else {
NSLog(#"Device is unable to send the request in its current state.");
}
}

the ui of "New Message" of Mail app?

How to implement the UI of "New Message" of Mail app in iPhone.?
Use the MFMailComposeViewController class.
Don't worry about UI to integrate mail in your app. Everything will be taken care by MFMailComposeViewController Framework. Add this framework and Write the below code
#import <MessageUI/MessageUI.h>
#interface ViewReminderViewController_iPhone : UIViewController
<MFMailComposeViewControllerDelegate>
{
UiButton *mailButton;
}
- (IBAction)EmailButton:(id)sender;
#end
#implementation ViewController
- (IBAction)EmailButton:(id)sender
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Your EMail Subject"];
//SET UP THE RECIPIENTS (or leave not set)
//NSArray *toRecipients = [NSArray arrayWithObjects:#"first#example.com", nil];
//[picker setToRecipients:toRecipients];
//NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
//[picker setCcRecipients:ccRecipients];
//NSArray *bccRecipients = [NSArray arrayWithObjects:#"four#example.com", nil];
//[picker setBccRecipients:bccRecipients];
//ATTACH FILE
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"MediaFiles"];
path = [path stringByAppendingPathComponent:MyFileName];
NSLog(#"Attaching file: %#", path);
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist?
{
NSLog(#"File exists to attach");
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/octet-stream"
fileName:#"DesredFileName.mov"];
}
//CREATE EMAIL BODY TEXT
NSString *emailBody = #"Your Email Body";
[picker setMessageBody:emailBody isHTML:NO];
//PRESENT THE MAIL COMPOSITION INTERFACE
[self presentModalViewController:picker animated:YES];
[picker release];
}
Delegate To Clear Compose Email View Controller
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES]; //Clear the compose email view controller
}

iphone mailcomposer

i have my tabbar and i can hide this tab bar by the following code below but when tapping cancle of iphone mail composer does not return to the default screen can you please guide how can i do this
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#""];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#""];
NSString *emailBody = #"";
[picker setMessageBody:emailBody isHTML:NO];
//[self presentModalViewController:picker animated:YES];
UIViewController *xyz=(UIViewController*)[myMarketsVicAppDelegate getMainTabbarRef];
[xyz presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
You must have to implement following Delegates.
UINavigationControllerDelegate
MFMailComposeViewControllerDelegate,
Like this
<MFMailComposeViewControllerDelegate,UINavigationControllerDelegate>.
Above might be an issue, because - If you have not implemented above delegate, It will give you compile time warnings but however it will execute.

Sending email in iPhone

In my application I have to send feedback to the client's email.
Here is my code,
-(void) send:(id) sender {
[self sendEmailTo:[txtTo text] withSubject:[txtSubject text] withBody:[txtBody text]];
}
-(void) sendEmailTo:(NSString *)to withSubject:(NSString *) subject withBody:(NSString*)body {
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
But this does not work. Is it require any type of SMTP setting or something else?
I tried apple's MailComposer sample but it also does not work.
Please help me.
I have posted this here, but for the sake of not clicking again here it is:
You need to include the MessageUI.framework into your project, and inside your header file you need to set the delegate:
#import <MessageUI/MessageUI.h>
#interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
MFMailComposeViewController *email;
}
#property (nonatomic, retain) MFMailComposeViewController *email;
Once you do that, you have a few delegate methods inside your implementation file you need to include (You should check to see the result, but I am trying to keep as little code as needed):
#synthesize email;
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[email dismissModalViewControllerAnimated:YES];
}
Wherever you want to use this, you need to initialize and set it up like this:
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:#"Testing"];
// Optional Attachments
NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:#"albumart.png"]);
[email addAttachmentData:artwork mimeType:#"image/png" fileName:#"albumart.png"];
// Body
[email setMessageBody:#"This is the body"];
// Present it
[self presentModalViewController:email animated:YES];
Try to use different format:
NSString *mailString = [NSString stringWithFormat:#"mailto:%#?subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];

embed mail compose in an iPhone app

I want my app to send mail. I can use the mailto: URL scheme, but it terminates my app when launching iPhone mail. The newsreader from The Independent (British paper) seems to bring up a mail compose view within the app. When you send or cancel, the app reappears immediately.
Does anyone know how to do this?
thanks,
You need to use 3.0 Message UI Framework!
#import <MessageUI/MessageUI.h>
#interface ViewReminderViewController_iPhone : UIViewController
<MFMailComposeViewControllerDelegate>
{
UiButton *mailButton;
}
- (IBAction)EmailButton:(id)sender;
#end
#implementation ViewController
- (IBAction)EmailButton:(id)sender
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Your EMail Subject"];
//SET UP THE RECIPIENTS (or leave not set)
//NSArray *toRecipients = [NSArray arrayWithObjects:#"first#example.com", nil];
//[picker setToRecipients:toRecipients];
//NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
//[picker setCcRecipients:ccRecipients];
//NSArray *bccRecipients = [NSArray arrayWithObjects:#"four#example.com", nil];
//[picker setBccRecipients:bccRecipients];
//ATTACH FILE
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"MediaFiles"];
path = [path stringByAppendingPathComponent:MyFileName];
NSLog(#"Attaching file: %#", path);
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist?
{
NSLog(#"File exists to attach");
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/octet-stream"
fileName:#"DesredFileName.mov"];
}
//CREATE EMAIL BODY TEXT
NSString *emailBody = #"Your Email Body";
[picker setMessageBody:emailBody isHTML:NO];
//PRESENT THE MAIL COMPOSITION INTERFACE
[self presentModalViewController:picker animated:YES];
[picker release];
}
Delegate To Clear Compose Email View Controller
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[self dismissModalViewControllerAnimated:YES]; //Clear the compose email view controller
}