在UIActionSheet中获取电子邮件客户端

时间:2016-01-19 09:26:06

标签: ios objective-c iphone xcode email

我想让电子邮件客户端成为一个Action,当我点击电子邮件客户端时,该电子邮件应该从该特定客户端发送。谁能告诉我如何实现它? Please click on this for image

它应该看起来像上面的图像。

2 个答案:

答案 0 :(得分:0)

希望这会对你有所帮助。

UIActionSheet* sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.title = @"Add Accounts";
sheet.delegate = self;
[sheet addButtonWithTitle:@"iCloud"];
[sheet addButtonWithTitle:@"Google"];
[sheet addButtonWithTitle:@"Yahoo"];
if (condition)
[sheet addButtonWithTitle:@"XYZ"];
sheet.cancelButtonIndex = [sheet addButtonWithTitle:@"Cancel"];

然后你必须从动作表创建itemclick的方法,你必须使用以下代码打开邮件应用程序

if ([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController * emailController = [[MFMailComposeViewController alloc] init];
    emailController.mailComposeDelegate = self;

    [emailController setSubject:subject];
    [emailController setMessageBody:mailBody isHTML:YES];   
    [emailController setToRecipients:recipients];

    [self presentViewController:emailController animated:YES completion:nil];

    [emailController release];
}
// Show error if no mail account is active
else {
    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"You must have a mail account in order to send an email" delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", @"OK") otherButtonTitles:nil];
    [alertView show];
    [alertView release];
}

注意,如果您想从应用程序本身发送电子邮件,可以使用 MFMailComposeViewController

答案 1 :(得分:0)

Apple没有提供API来获取客户端。您必须自己设计ActionSheet图标,并在MFMailComposeViewController中点击“发件人”字段,您必须使用合适的电子邮件ID自动填充该字段。