Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Mobile-Applications iPhone - MFMailcomposeviewcontroller example

Have Programming Question? Ask it here!
 
 
 


Java Coder
iPhone - MFMailcomposeviewcontroller example
2 Answer(s)      3 years and 4 months ago
Posted in : MobileApplications


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

Thanks!!


Advertisement
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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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 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
iphone  hiii, how can we use table recursively in iphone
iphone
iphone  How can connect with the other database in iphone application(like... MYsql or oracle) is this dirctly possible
iphone
iphone  hello... i want to make first iphone application . How can i make it plz help me
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
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 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 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
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 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
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
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
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
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
iPhone Graphics
iPhone Graphics  Hi, How to create iPhone Graphics? I am learning to crate UI Design for iPhone and iPad. Thanks
Iphone call
Iphone call  Do you have other method to make a call on Iphone,without openUrl
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
Iphone Tutorial
Iphone Tutorial  Hi, I am a new in this mobile applications segment. From where i will get the information about iphone tutorial or Iphone Development Tutorials. Please suggest the resouces......... Thanks
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 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
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
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
iPhone
iPhone       Apple iPhone 3G is a multi-touch smartphone that has successfully combined multimedia, email, business and internet into a single platform. The iPhone
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
NSZombieEnabled iPhone
NSZombieEnabled iPhone  NSZombieEnabled Trouble in setting How can i set the NSZombieEnabled in iPhone application to track unmanaged memory
iPhone Single Tap and Double Tap Example
iPhone Single Tap and Double Tap Example The example discuss about single tapping / double tapping on UIView and it also explains how to represent the UIIMage... UIViewContentModeBottomLeft UIViewContentModeBottomRight In the example, to detect the end
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
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 - 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
Iphone Developmnt
Iphone Developmnt  i am making an application in ios, for ipad or iphone, what i want to know is that can i provide an option of changing the theme , or can i separate my code from the theme... so that when giving my product
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 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 nsurlrequest authentication
iphone nsurlrequest authentication   How to authenticate a form in iPhone Application
libxml2.2.dylib iphone
libxml2.2.dylib iphone  Hi, I added the libxml2.2.dylib in iPhone application, still its not able to compile the XML processing code. What to do? Thanks   Hello, You must be getting the linking errors. You should
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 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
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
what is json in iphone sdk
what is json in iphone sdk  What is json in iphone sdk? Is this a library and when i need to include JSon in my iPhone SDK App
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
 

 

 

DMCA.com