如何使用MFMailComposeViewController设置ToRecipients

use*_*647 8 iphone xcode objective-c mfmailcomposeviewcontroller

我正在尝试收到我选择发送电子邮件的电子邮件.但我不知道如何setToRecipients我在MFMailComposeViewController视图中选择的用户.

if ([MFMailComposeViewController canSendMail])
    {
        mailer = [[MFMailComposeViewController alloc] init];

        mailer.mailComposeDelegate = self;
        [mailer setSubject:@"A Message from blablabl"];

        NSMutableArray *usersTo = [[NSMutableArray alloc] init];
        toRecipients = usersTo;
        [mailer setToRecipients:toRecipients];

        NSString *emailBody = @"blablablabal";

        [mailer setMessageBody:emailBody isHTML:YES];

        // only for iPad
        // mailer.modalPresentationStyle = UIModalPresentationPageSheet;

        [self presentModalViewController:mailer animated:YES];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                                                        message:@"Your device doesn't support the composer sheet" 
                                                       delegate:nil 
                                              cancelButtonTitle:@"OK" 
                                              otherButtonTitles: nil];
        [alert show];
    }
Run Code Online (Sandbox Code Playgroud)

委托 http://pastie.org/3281814

Mic*_*ann 27

这里有几件事是错的.

1)

MFMailComposeViewController的setToRecipients方法需要一个已设置收件人的不可变数组.

2)

而你将它设置为一个空白的可变数组.

尝试这样的事情:

NSArray *usersTo = [NSArray arrayWithObject: @"nobody@stackoverflow.com"];
[mailer setToRecipients:usersTo];
Run Code Online (Sandbox Code Playgroud)

你应该看到它有效.


Ten*_*kar 5

   MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
   NSArray *toRecipients = [NSArray arrayWithObjects:@"first@gmail.com",@"second@gmail.com",nil];   
   [picker setToRecipients:toRecipients];
Run Code Online (Sandbox Code Playgroud)