gpt4 book ai didi

iphone - 在 iPhone 应用程序中撰写邮件

转载 作者:IT王子 更新时间:2023-10-29 08:09:47 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个关于页面。我想放置一个圆形的矩形按钮,当我按下它时,我将能够向公司发送一封带有嵌入式电子邮件地址的电子邮件。

是否有任何教程可以做到这一点?

提前致谢。

最佳答案

代码如下:

objective-C :

(不要忘记将 messageUI 框架添加到您的项目中!!!)

首先导入消息库:

#import <MessageUI/MessageUI.h>

然后像这样将您自己标记为代表:

@interface MYViewController () <MFMailComposeViewControllerDelegate>

然后拉起 Composer (如果用户在他们的设备上设置了电子邮件):

- (IBAction)emailButtonPressed:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *composeViewController = [[MFMailComposeViewController alloc] initWithNibName:nil bundle:nil];
[composeViewController setMailComposeDelegate:self];
[composeViewController setToRecipients:@[@"example@email.com"]];
[composeViewController setSubject:@"example subject"];
[self presentViewController:composeViewController animated:YES completion:nil];
}
}

然后处理委托(delegate)回调并关闭 Composer :

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
//Add an alert in case of failure
[self dismissViewControllerAnimated:YES completion:nil];
}

SWIFT 3:

导入相关库:

import MessageUI

像这样将您的 View Controller 标记为委托(delegate):

class MyViewController: UIViewController, MFMailComposeViewControllerDelegate {

拉起 Composer (如果用户在他们的设备上设置了电子邮件):

@IBAction func emailButtonAction(_ sender: UIButton) {

if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients(["example@gmail.com"])
mail.setSubject("Example Subject")
mail.setMessageBody("<p>Test</p>", isHTML: true)
present(mail, animated: true)
}
}

处理委托(delegate)回调并解雇 Composer :

func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}

关于iphone - 在 iPhone 应用程序中撰写邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6061039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com