要在iOS端使用HTML发送短信而不跳出弹框,发短可以使用MFMailComposeViewController和UIActivityViewController进行邮件和消息分享,信何以(yi)下(xia)是不跳详细步骤:(图片(pian)来源网络,侵删)
1、出弹导入所需的发短框架

在项目中导(dao)入MessageUI框架,以便使用MFMailComposeViewController和(he)UIActivityViewController。信何

import MessageUI
2、不(bu)跳创建发送邮件的出弹方法

创建一个名为sendEmail的方(fang)法,用于显示邮件分(fen)享界面。发短
func sendEmail() { if MFMailComposeViewController.canSendMail() { let mail = MFMailComposeViewController() mail.mailComposeDelegate = self mail.setToRecipients(["example@example.com"]) mail.setSubject("邮件主题(ti)") mail.setMessageBody("邮件正文",信何 isHTML: true) present(mail, animated: true, completion: nil) } else { print("无法发(fa)送邮件") }}3、实现邮件分享的不跳代理方法
实现MFMailComposeResultDelegate协议的方法,以处理邮件发送结果。出弹
extension YourViewController: MFMailComposeResultDelegate { func mailComposeController(_ controller: MFMailComposeViewController,发短 didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) }}创建一个(ge)名为sendMessage的方法,用于显示(shi)消息分享界面。不跳
func sendMessage() { let messageVC = UIActivityViewController(activityItems: ["短信内容"], applicationActivities: []) messageVC.popoverPresentationController?.sourceView = self.view // 设置弹出视图的来源为当前视图 messageVC.excludedActivityTypes = [.airDrop, .assignToContact, .addToReadingList] // 排除不需(xu)要的分享类型 present(messageVC, animated: true, completion: nil)}在需(xu)要发送邮件和消息的地方(fang)调用相应的方法,可以添加按钮点击事件或手势识别等。
@IBAction func sendButtonTapped(_ sender: UIButton) { sendEmail() // 发(fa)送邮件(jian) sendMessage() // 发送消(xiao)息}通过以上步骤,可以在iOS端使用HTML发送短信而不跳出弹框。
网 址:http://bindebake.cn/
邮 箱:19536963@qq.com
地 址:上海市长宁66号