how to let user choose the mail receiver? - iphone

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.

Related

Social sharing url of current webview iPhone. ( Xcode)

so I have my app setup with share action button that shares the current URL to Twitter or Facebook however when I click the Facebook button it shows a Twiiter share sheet. The (Tiwtter option works fine)
After I click the FACEBOOK option, when testing on iPhone the standard twiiter share sheet appears.
- (IBAction)social:(id)sender {
UIActionSheet *share = [[UIActionSheet alloc] initWithTitle:#"Pass on the news!" delegate:self cancelButtonTitle:#"OK" destructiveButtonTitle:nil otherButtonTitles:#"Post to Twitter", #"Post to Facebook", nil];
//You must show the action sheet for the user to see it.
[share showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
//Each button title we gave to our action sheet is given a tag starting with 0.
if (actionSheet.tag == 0) {
//Check Twitter accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewController *tweetSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet addURL:self.newsItemWebView.request.URL]; //This is setting the initial text for our share card.
[tweetSheet setInitialText:#"Check out this article I found using the 'Pass' iPhone app:, "];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:tweetSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't send a tweet right now, make sure you have at least one Twitter account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
} else if (actionSheet.tag == 1) {
//Check Facebook accessibility and at least one account is setup.
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *facebookSheet =[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebookSheet addURL:self.newsItemWebView.request.URL];
//This is setting the initial text for our share card.
[facebookSheet setInitialText:#"Check out this article I found using the 'Pass' iPhone app:"];
//Brings up the little share card with the test we have pre defind.
[self presentViewController:facebookSheet animated:YES completion:nil];
} else {
//This alreat tells the user that they can't use built in socal interegration and why they can't.
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry" message:#"You can't post a Facebook post right now, make sure you have at least one Facebook account setup and your device is using iOS6 or above!." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
}
}
You are using actionSheet.tag which will be the same for the entiere actionsheet.
If you want to know which button is pressed you should use buttonIndex in your if statements.
Even better is to use UIActivityViewController.
NSArray *items = #[self.newsItemWebView.request.URL];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.completionHandler = ^(NSString *activityType, BOOL completed) {
// do any thing you want when the user finishes the share activity.
// Like present a message that that activity has completed or not.
};
[self presentViewController:activityViewController animated:YES completion:nil];

Email Signature App 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...

How to show email sent notification ipad

I've a mail controller which successfully sends email.
But I want to show a notification of "Email Sent Successfully" as the email is sent. Is there a way to do that?
Thanks.
If you are using MFMailComposeViewController, you can use its delegate method.
1. Set the delegate: mailController.mailComposeDelegate=self;
2. Then use the delegate method `
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
if(result == MFMailComposeResultSent)
{
UIAlertView*sentalert=[[UIAlertView alloc] initWithTitle:#"Mail Sent succesfully!" message:nil delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[sentalert show];
[sentalert release]; // if not using ARC
}
[self dismissModalViewControllerAnimated:YES]; //Dismiss your mail controller
}

MFMailComposeViewController ModalView crashes the iOS5 application

I have an iOS TabBar Application with tabbarcontroller and navigationcontroller.
In my detail view wich is pushed from my first tab tableviewcontroller i have sharing navigationItem.rightBarButtonItem with email sharing.
I have the following code for this:
- (void)share
{
UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:#"Send" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Email",nil];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[popupQuery showInView:self.view];
[popupQuery release];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
if ([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[picker setMailComposeDelegate:self];
[picker setSubject:#"New theme"];
NSString *emailBody = #"Hi there";
[picker setMessageBody:emailBody isHTML:NO];
[self resignFirstResponder];
picker.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:picker animated:NO];
[picker release];
}
else{
}
}
}
The app shows me the composing view but when i'm trying to do something with this view (e.g. to pick up the address or to spell something) - app crashes with SIGTRAP.
The app crashes only in iOS5, iOS5.1. In iOS4.2.1 everything works perfect.
What's the problem? Any ideas?
Per the docs, I'd suggest calling [MFMailComposeViewController canSendMail] class method before creating MFMailComposeViewController. I also generally don't have that [self resignFirstResponder] line. I gather you're crashing before your mailComposeController:didFinishWithResult:error method is invoked?
Thank you guys for your help and your time.
It was absolutely insane bug. Project has a cyrillic name. I just renamed it to latin name and now everything works fine. My fault :( Thanks Evgeniy Shurakov for the help.

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