如何在iOS中仅允许一个邮件收件人

时间:2013-01-05 17:53:35

标签: ios xcode email ios6 mfmailcomposeviewcontroller

我正在创建一个“联系我们”按钮,允许用户通过电子邮件联系我们的支持团队(我使用的是iOS 6)。但我希望Mail Composer仅向我们的支持团队发送电子邮件,不允许用户添加或删除收件人电子邮件地址。

DemoProject.h

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

@interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate> // Add the delegate
- (IBAction)showEmail:(id)

DemoProject.m

 - (IBAction)showEmail:(id)sender {
    // Email Subject
    NSString *emailTitle = @"Test Email";
    // Email Content
    NSString *messageBody = @"iOS programming is so fun!";
    // To address
    NSArray *toRecipents = [NSArray arrayWithObject:@"support@app.com"];

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
    [mc setSubject:emailTitle];
    [mc setMessageBody:messageBody isHTML:NO];
    [mc setToRecipients:toRecipents];

    // Present mail view controller on screen
    [self presentViewController:mc animated:YES completion:NULL];

}

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail sent failure: %@", [error localizedDescription]);
            break;
        default:
            break;
    }

    // Close the Mail Interface
    [self dismissViewControllerAnimated:YES completion:NULL];
} `

1 个答案:

答案 0 :(得分:2)

你无法限制。您可以预填该字段,但是您无法限制用户编辑收件人。