views:

55

answers:

2

Hey everyone

i have a question regarding the call-methods handling in object-c.

I downloaded the apple sample code for the mail composer (http://developer.apple.com/iphone/library/samplecode/MailComposer/Introduction/Intro.html).

When the user touches the "Compose Mail"-Button in the sample-code the Methode

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

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


    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"]; 

    [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];
}

will be loaded and the mailcomposerview appears.

After the user sends the mail or cancels it the following methode will be called

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    NSLog(@"MCVC mailComposeController");
    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];
}

in which you can implement your code.

My Question now is how can i get for example the data of "toRecipients", "ccRecipients", "setMessageBody", "setSubject" etc.?

Is this even possible? I dont know how to use the getter in the "- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error"-Methode

If i forgot any informations you need i will post them :)

Thanks for everyone who can help me out :)

A: 

From the Apple API:

Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.

Looking at this, and also trying out various names that would be appropriate for the ivars in the didFinishWithResult: method, it seems it is NOT possible to get this information from the prebuilt MFMailComposeViewController

you could subclass this class or roll your own to get the functionality..but that seems to be the only way to do it.

Jesse Naugher
A: 

@Jesse Naughter First of all thanks for the answer.

I don't wont to modifiy MFMailComposeViewController. Rather than that i just want to use the MFMailComposeViewController the way it is.

I need something like

[picker getToRecipients:[0]];

so that i am able to save the mail on our company database and not just on the iphones of our sales team.

Right now the sales team has to save every mail they wright seperatly on our database day after day at the end of the day.

Thats why i want to wright an app that does this automaticly so that they dont have to take care of that everyday.

I thought that i could save the content of "setSubject", "setToRecipients", "setCcRecipients", "setBccRecipients", "setMessageBody" after the "send" Button has been touched and "MFMailComposeResultSaved" is delivert as a result of the user action.

The problem is that i cant use "picker" in the

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

methode because its in the scope of the

-(void)displayComposerSheet

Methode and the second thing is that there doesnt seem to exist a getter-methode like "getToRecipients" and another problem is that i dont know how to get the first element of the array. I just started to wright in object-c and its a little bit unusual compared to the language i used till now :)

If i get this right in the

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error

Methode the "MFMailComposeViewController" controller is passed to, thats why i thought that i could use "controller" instead of "picker" but this didn't work either.

Any help would be appreciated ;)

locdog