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



Home Answers Viewqa Mobile-Applications iPhone - MFMailcomposeviewcontroller example
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
iPhone - MFMailcomposeviewcontroller example
2 Answer(s)      3 years and 9 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 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
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
Advertisements
 

 

 

DMCA.com