Email Signature App Iphone - iphone

I am making an email signature application that allows user to make signatures and use them to send with emails, Their is signature name(Text Field), content(Text View) and image(Image View) and i am saving them in Database so that if the user selects the signature name from the table view that is on the second view the preview will show up on the same view like if i select signature 1 from table view then in preview section the signature image should show up with the signature content in (Text View), and then on the same view we press send(Button) the text and image from the Text View of preview section will be copied to clipboard and then in third view i can paste it in the message section and send the email, is it possible to do that if yes how can i implement it or any other idea how to do this ?

i have this one method for send email with image and message .. just add MFMessageComposeViewControllerDelegate in .h file and add framework MessageUI.framework in your project
-(void)sendMailWithImage:(NSString *)message Image:(UIImage *)image{
if ([MFMailComposeViewController canSendMail])
{
UIImage *tempImageSave=image;
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
NSString *mailBody = message;
NSData *imageData = UIImagePNGRepresentation(tempImageSave);
[mailComposeViewController addAttachmentData:imageData mimeType:#"image/png" fileName:#"Testing"];
[mailComposeViewController setMessageBody:mailBody isHTML:NO];
mailComposeViewController.mailComposeDelegate = self;
[self presentViewController:mailComposeViewController animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"e-Mail Sending Alert"
message:#"You can't send a mail"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
and this bellow method is delegate method of MFMessageComposeViewControllerDelegate
#pragma mark - MFMessage Delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent)
{
NSLog(#"\n\n Email Sent");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
i hope this help you...

Related

After sending an in App email with photo attachment the Email window won't dismiss even when I hit send or cancel

I'm in a bit of trouble, I've spent half a day working onto this issue I have with no major results after all deprecations in iOS6 and other issues. This iOS app, has a send email option when after pushing a button, the app takes a screenshot of my WebView, attaches it to the email and from there, have the normal options to cancel or send the email and return to the app. I made it to the part where the email pops up, and actually 2 issues here: one is that after pressing either cancel or send, the email view won't dismiss, the app is stuck in the email view. And the second issue I have is the image that gets attached is just a tiny icon (blue with an question mark just like it is not recognised or is missing...
Can someone please point me in the right direction as I feel like I'm going crazy. I've researched the net backwards and forwards with no luck. Many similar threads but different issues not exactly related to my issues unfortunately. Sorry, and thanks in advance.
Here is my code:
// in my LiveView.h file
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <MessageUI/MessageUI.h>
#import "CamSetup.h"
#interface LiveView : UIViewController < MFMailComposeViewControllerDelegate , ADBannerViewDelegate >
....
-(IBAction)shotAndSend:(id)sender;
// in my LiveView.m file:
- (void)mailComposer:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSLog(#"in didFinishWithResult:");
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(#"cancelled");
break;
case MFMailComposeResultSaved:
NSLog(#"saved");
break;
case MFMailComposeResultSent:
NSLog(#"sent");
break;
case MFMailComposeResultFailed: {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error sending mail",#"Error sending mail")
message:[error localizedDescription] delegate:nil
cancelButtonTitle:NSLocalizedString(#"test",#"test")
otherButtonTitles:nil];
[alert show];
break;
}
default: break;
}
[self dismissViewControllerAnimated:NO completion:Nil];
}
-(IBAction)shotAndSend:(id)sender
{
UIGraphicsBeginImageContext(_myWebView.frame.size);
[_myWebView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imageData = UIImageJPEGRepresentation (image, 2.1);
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController * mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer addAttachmentData:imageData mimeType:#"image/jpeg" fileName:#"attachment.jpeg"];
[mailComposer setSubject:#"A screenshot from my App"];
[mailComposer setToRecipients:[NSArray arrayWithObjects:#"123#yexample.com", nil]];
[self presentViewController: mailComposer animated:YES completion:NULL];
}
}
Your code isn't working because you have the wrong method. You have:
- (void)mailComposer:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
but it should be:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
You need a delegate of your view that will dismiss that view for you. The fact that you don't see the log indicate you that you haven't implemented correctly the delegation protocol. Take a look at some example in the apple documentation.

MFMailComposeViewController in the delegate

The question deals with an application which uses many views in a UINavigation controller Style.
I have a simple function in my delegate which can be used by all views to plot-out error message
// In Appdelegate.m
-(void)popErrorWindow:(NSString *)theError
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:theError
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Report",nil];
[alert show];
[alert release];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1)
{
NSLog(#"report");
[self mailIt:#"error name"];
}
}
Now, wanting to have a mechanism that will email the error along with some other data I have created this:
-(void)mailIt:(NSString *)theError {
NSLog(#"Mail it");
pickerMail = [[MFMailComposeViewController alloc] init];
pickerMail.mailComposeDelegate = self;
[pickerMail setSubject:#"error via email"];
NSMutableString *body = [NSMutableString string];
[body appendString:#"Error XXX "];
[pickerMail setMessageBody:body isHTML:YES];
// Problem here:
[self.window presentModalViewController:pickerMail animated:YES];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Problem here:
[self.window dismissModalViewControllerAnimated:YES];
//NSLog(#"mail was sent");
}
The problem is in self.window , which is not the right way to access this from the delegate,
I still want to have the mail element in the delegate as all views can call the error alert, and I would like to have only one place for this mechanism.
How should I do it from inside the delegate, what should replace the self.window?
Perhaps reimplementing popErrorWindow: and mailIt: in a category on UIViewController. This way you have access to the top-level view controller to call presentModalViewController and dismissModalViewControllerAnimated on.
Alternatively you can do this in a subclass of UIViewController and then make your other custom view controller's subclass of that. The downside to this method is when you have subclasses of classes other than UIViewController
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error
{
[controller dismissModalViewControllerAnimated:YES];
}
EDIT :
The - (void)presentModalViewController:(UIViewController *)vc and - (void)dismissModalViewControllerAnimated:(BOOL)animated methods are an UIViewController instance method, so you cannot use it with an UIWindow.
In order to present your mail controller with a nice animation, you can do that :
UIViewController *aController = self.navigationController.presentedViewController;
[aController presentModalViewController:pickerMail animated:YES];

IOS development, using UITabBarController and UIImagePickerController, How to go from one tab to another?

I can't seem to find an answer for this, or maybe can't understand the things people wrote over the web...
I have a UITabBar with 3 tubs.
One of the tabs is a UIImagePickerController. This TabBar Item is connected to a view controller that i set also as the delegate for the Image picker (camera).
I want that then someone take a photo or press cancel, The first TabBar item will be choosen (don't want to stay in the TabBar that holds the camera).
My question is, How do I "talk" with the TabBar controller from a view controller that is in one of the TabBar items?
my code in the TakePhotoViewController.m file that is in the 3rd TabBer item and i want to go the first item.
-(void) viewWillAppear:(BOOL)animated{
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.allowsEditing = NO;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imgPicker animated:YES];
}
and the delegate methods:
#pragma mark -
#pragma mark - UIImagePicker delegate methods
//saving the image that was taken
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
[picker release];
}
//alerting the user if the images was saved or not
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
//if user is cancelling the camera
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[picker release];
}
Thank you very much,
Erez
[self.tabBarController setSelectedIndex:1];
You can pass your desired tab index value instead of 1.

Problem displaying MFMailComposeViewController modal view

I'm having problems displaying a modal view for sending emails (MFMailComposeViewController). I'm trying to display this modal view from a detailed view that was pushed on the stack by selecting a cell in an initial table view. My problem is that although the MFMailComposeViewController does display, I do not get the Send and Cancel buttons that I usually go with the MFMailComposeViewController view. I just get the 'Back' button of my detail view in my navigation bar.
My detail view is a subclass of UIViewController conforming to MFMailComposeViewControllerDelegate,UINavigationControllerDelegate protocols:
And my methods for sending emails is:
-(void)sendEmail {
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mailComposer setToRecipients:[NSArray arrayWithObjects:#"test#gmail.com",nil]];
[mailComposer setSubject:#"Subjecy"];
[mailComposer setMessageBody:#"Body" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
[mailComposer release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message Failed" message:#"Your message failed to send" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Many thanks for any help.
I had a similar problem when displaying the email window on an iPad with
[self presentModalViewController:mailComposer animated:YES];
The Send and Cancel buttons were partially cut off because the whole window was shifted up by approximately 20 or 30 pixels. Strangely, this was only happening in Portrait mode when the home button was at the bottom.
The solution was to set the main window size to iPad Full Screen in MainWindow.XIB
It was set to None by default.
Rich

how to let user choose the mail receiver?

in my app i used the code below to handle the messages send from iphone i want to know how to let him choose between contact us and tell a friend like other apps how can i make this issue ?
the code :
-(IBAction)sendEmail {
//Create a new mailComposer object and set the mailComposeDelegate (required).
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
//Set Fields such as Subject, recipients, and message body.
[mailComposer setToRecipients:[NSArray arrayWithObjects:#"info#Myweb.com",nil]];
[mailComposer setSubject:#"App Feadback"];
//Present the mail view controller
[self presentModalViewController:mailComposer animated:YES];
}
//release the mailComposer as it is now being managed as the UIViewControllers modalViewController.
[mailComposer release];
}
//MFMailComposeControllerDelegate method that handles success or failure
//and dismisses the mailComposer
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
if (result == MFMailComposeResultFailed) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Message Failed" message:#"Your message failed to send" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
For Contact Us, you have to prefill your mail address to mailComposer.setToRecipient. as you have done.
And for tell a friend, you have to collect your friend's email address prior the mail composer in view. e.g. using Address book person picker control.
Whatever you do, MFMail composer will not allow you to do anything without the knowledge of the user. The user can delete/add in the mailto field when it pops up.