Home Answers Viewqa Mobile-Applications iPhone - MFMailcomposeviewcontroller example

 
 


Java Coder
iPhone - MFMailcomposeviewcontroller example
2 Answer(s)      2 years and a month ago
Posted in : MobileApplications

Hi! I'm looking for a mfmailcomposeviewcontroller example for both iPhone and iPad. Any suggestion??

Thanks!!

View Answers

April 5, 2011 at 4:29 PM


To configure a mail in your iPhone / iPad application, import the given class in your header file. And add a new framework called "MessageUI.framework" to your frameworks folder.

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

April 5, 2011 at 4:42 PM


We also need to create a label to show the message and button action to perform actions as showPicker, displayComposerSheet, launchMailAppOnDevice as given below..

    -(IBAction)showPicker:(id)sender
    {   
        Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
        if (mailClass != nil)
        {
            // We must always check whether the current device is configured for sending emails
            if ([mailClass canSendMail])
            {
                [self displayComposerSheet];
            }
            else
            {
                [self launchMailAppOnDevice];
            }
        }
        else
        {
            [self launchMailAppOnDevice];
        }
    }

    -(void)displayComposerSheet 
    {
        MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
        picker.mailComposeDelegate = self;

        [picker setSubject:@"Hello from California!"];


        // Set up recipients
        NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
        NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
        NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

        [picker setToRecipients:toRecipients];
        [picker setCcRecipients:ccRecipients];  
        [picker setBccRecipients:bccRecipients];

        // Attach an image to the email
        NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
        NSData *myData = [NSData dataWithContentsOfFile:path];
        [picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];

        // Fill out the email body text
        NSString *emailBody = @"It is raining in sunny California!";
        [picker setMessageBody:emailBody isHTML:NO];

        [self presentModalViewController:picker animated:YES];
        [picker release];
    }
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    message.hidden = NO;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            message.text = @"Result: canceled";
            break;
        case MFMailComposeResultSaved:
            message.text = @"Result: saved";
            break;
        case MFMailComposeResultSent:
            message.text = @"Result: sent";
            break;
        case MFMailComposeResultFailed:
            message.text = @"Result: failed";
            break;
        default:
            message.text = @"Result: not sent";
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
}

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
    NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
    NSString *body = @"&body=It is raining in sunny California!";

    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}

You can find a running example in Apple website for developers too :-)









Related Pages:
info button iphone example
info button iphone example  I'm looking for a simple info button example in iPhone XCode. Thanks
uialertview example iphone
uialertview example iphone  Hi, How to write uialertview example iphone code? Thanks   Hi, Please check UIAlertView Example. Thanks
iPhone Radio Button Example
iPhone Radio Button Example  Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two images on UIButton 1) selected and 2) unselected ..what i want is, when a user
iphone avfoundation
iphone avfoundation  What is iphone avfoundation and why it is required? Can anyone show how to implement the AVFoundation in iPhone application with example or tutorial? Thanks
iPhone resignfirstresponder
iPhone resignfirstresponder  Hi, Provide me a good example of iPhone resignfirstresponder. I need a code to hide keyboard when use clicks outside the text box. Thanks   Hi, You can use the following code
GLImageProcessing iphone sample
GLImageProcessing iphone sample  Hi, From where I can download the GLImageProcessing example for iPhone? Thanks   Hi, The GLImageProcessing sample for iPhone shows how to use OpenGL ES libraries to bright, sharp
MapView Example in iPhone
MapView Example in iPhone The example illustrate how to embed or display a MapView in iPhone SDK UIView based application. To embed a Map in your iphone... on UIView. It should look like the given image. Download code of MapView Example
Iphone hello world example
Iphone hello world example In this tutorial an iphone based hello world example is demonstrated. Also some relevant information under based is provided which... applications. So lets start building your iphone first hello world example. Before
iPhone SDK UIAlertView
iPhone SDK UIAlertView  Hi, How can i use the iPhone UIAlertView to create a message box. Can any help or provide example or online reference. Thanks
Iphone Current Date Application
Iphone Current Date Application  Hi, I am a beginner in the mobile web application segment. How can i develop Iphone Current Date Application. I need the online help guide or example about iphone current date format. Thanks
Iphone Table View Application
Iphone Table View Application  Hi, How to use Table View Application in Iphone? What parameters i have to follow to develop the Table view Apps with iphone? Please guide me or suggest any online example for reference. Thanks
share data iphone sdk
share data iphone sdk  How to share data in iPhone application? Actually i want the sharing feature in my iPhone application. Thanks!   You can use the emailing feature in your iPhone application to the share data
UINavigationBar Color - iPhone example
UINavigationBar Color - iPhone example The example is discussing about how to change the color of UINavigationBar. In iPhone applications you can customize...;Build" it should look like the given image.. In the example, we have
iphone - EXC_BAD_ACCESS
iphone - EXC_BAD_ACCESS  What cause this "iphone - EXCBADACCESS.... For example, you have created the NSArray or NSMutable array , initialization.... That could be the cause of iphone - EXCBADACCESS error
multiple language support iPhone
an application in iPhone that can support multiple languages.   Yes, iPhone/iPad applications support the multi language applications. To create your iPhone... the project location and create two project files for example en.lproj
Iphone Current Time Example
Iphone Current Time Example After going through this iphone SDK example, you will be able to show the current time on UILable. In this example we have used a UILable to show the output(current time) of the application and an UIButton
iPhone Font Size
iPhone Font Size In this example we are going to change the iphone font size and color. You can change the font size and font type using the Inspector that resides in Interface Builder->Tools. It has the number of font
How to Make iPhone Window Application
How to Make iPhone Window Application  Hi, For Making iphone window application, what parameters i have to follow or provide example related to iphone window application. Thanks
Hello World iphone Example
Hello World iphone with Example In the given tutorial you will be creating a small iphone application called "hello world app" using interface builder, that will run in the iphone simulator. Before going into deep
iphone
iphone  hiii, how can we use table recursively in iphone
How to Create Segment Application with iPhone
How to Create Segment Application with iPhone  Hi, i am fresher in iphone application. How can i will create segment application in iphone. So, kindly help me or provide online example reference. Thanks
Page curl effect iPhone SDK
Page curl effect iPhone SDK  How to get the page curl effect in my iPhone application? Please suggest or give an example to get the page curl effect in iPhone SDK application. Thanks.   In objective c there is a method
iphone button example
 iphone button example In this tutorial we will tell you how to change the type of button in Interface Builder. There are six types of iPhone button, each has used for different purpose.  1. Custom  2. Rounded
iphone
iphone  hello... i want to make first iphone application . How can i make it plz help me
iphone
iphone  How can connect with the other database in iphone application(like... MYsql or oracle) is this dirctly possible
How to Convert NSStringe into Uppercasestring iPhone
check the iPhone NSString uppercaseString() example. Thanks   Hi, For how to convert nsstring into uppercasestring in iphone Application. Please... how to convert nsstring into uppercasestring in iphone Application. Thanks
OpenGL ES For Iphone
and just started playing around with iPhone development. From google, it seems that iphone uses a special type of opengl (openGL ES). What are the languages... ES is not unique to the iPhone. OpenGL ES is a reduced version of the OpenGL
UIScrollView Example iPhone
UIScrollView Example iPhone UIScrollView is the superclass of several... iphone application window. That means you can adjust the size of view according... to set the frame and contentSize as well... frame size is the actual size of iPhone
iphone text field example
iphone textfield with example   In this iphone example you are going to see...how to add the value of two different textfield and printing it in another textfield. This is a quite easy! What all we have to do is to take three
iPhone Application Icon
iPhone Application Icon The example will illustrate how to add an icon on the iPhone application in Xcode. Before adding the application icon in iPhone make... an application icon in iPhone simulator.. add the "png" icon that you want
How to Create Quiz Application using iPhone
iphone application Programming Language. my question is that how to create a quiz application using iPhone. Please provide online reference to study and example. Thanks,   Hi, It is very easy to create a quiz application for iphone
iPhone MapView Current Location
iPhone MapView Current Location This is a simple MKMapView example in iPhone for the beginners. In the example we'll discuss about how to display a map... as current location but on running the application in iPhone it will give you
How to Changing Toolbar Color using iPhone Application ?
the online reference or example of how to change toolbar color in iPhone Apps...How to Changing Toolbar Color using iPhone Application ?  Hi, i have developing a small application to changing the toolbar color in iphone. But i
iPhone SDK Examples
While developing the iPhone program, many times you need some code to copy... small example code that you can copy and paste in your code. Small examples.... are presented here. We will discuss all the UI and other components of the iPhone SDK
splash screen time delay iphone
splash screen time delay iphone  How can i delay the splash screen?   How to delay splash screen in iPhone/iPad/ Objective C Splash scree.... For example, display default.png for 5 seconds. - (void
iPhone UILabel Color
iPhone UILabel Color In this example we'll discuss about the UILabel class... the appearance of text in your iPhone applications. Final application will look alike... of static text on label in our applications. For example if you wanted to identify
NSString CapitalizedString - Iphone example
NSString CapitalizedString - Iphone example Converting a first character of string to upper case (case changes): In this example, we are going to show you how to change the first character of the given string into uppercase. Create
Embedding HTML in iPhone App
Embedding HTML in iPhone App This example illustrate you how to embed the HTML in iPhone application. To embed the HTML file we required a UIWebView... to embed HTML into UIWebView iphone app - (void)viewDidLoad { NSString
How to Define Text Field Validation iPhone
How to Define Text Field Validation iPhone  Hi, Can anybody explain me how to define textfield validation iPhone program. please phone online help reference or example. Thanks
iPhone Splash Screen
iPhone Splash Screen In this example, I'm going to show you how to create splash screen in iphone apps. The motto behind showing splash screen is to show... in iphone apps, just create a "Default.png" image and put that image
Current Date iPhone SDK
Current Date iPhone SDK In this example, you'll find out how to get current date & day in iPhone SDK. We'll also write a method to print the day and date...! If not lets first find out what is NSdateFormatter in iPhone SDK programming
iPhone SDK Comparing Strings
iPhone SDK Project. To compare the Strings you will have to use... with == operator. In the following example code I have compared the two strings...;        } The above example is the proper way
iPhone String Match
iPhone String Match In this "String match" example we... that are used to search, compare and sort the strings in cocoa framework. For example... and comparing characters or substrings within the given strings. Let's take an example
Iphone Show Current Date & Time
Iphone Show Current Date & Time In the previous examples, we have printed current date and time separately in iphone simulator. But in this example we are going to show you how to print both current date and current time in iphone
iPhone Input Field, iPhone Input Field Tutorial
This is a very simple "iPhone input field" example that will show you how to use...iPhone Input Field Generally, input fields are used to take input from the users.  In iPhone application we can use Text Field to take the input. 
Iphone keypad app
Iphone keypad app The given sample "Iphone keypad app" is going to show you how to hide keyboard or number pad and return to the actual screen. We can see it with the help of this example...in which we are going to take

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.