gpt4 book ai didi

swift3 - 使用 MFMessageComposeViewController 发送短信

转载 作者:行者123 更新时间:2023-12-01 22:19:21 25 4
gpt4 key购买 nike

我想让我的应用发送短信,但我当前的代码不起作用,步骤如下:

import MessageUI

添加类:

MFMessageComposeViewControllerDelegate

然后我用了一个按钮:

 @IBAction func Messages(_ sender: UIButton) {


if MFMessageComposeViewController.canSendText() == true{
let recipients:[String] = ["1500"]
let messageController = MFMessageComposeViewController()
messageController.messageComposeDelegate = self // implement delegate if you want
messageController.recipients = recipients
messageController.body = "Your_text"
self.present(messageController, animated: true, completion: nil)

func messageComposeViewController(controller: MFMessageComposeViewController,
didFinishWithResult result: MessageComposeResult) {

// Dismiss the message compose view controller.
controller.dismiss(animated: true, completion: nil)}

}}

并使用函数:

 func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {}

我错过了什么?谢谢。

最佳答案

@IBAction func Messages(_ sender: UIButton) {   
if MFMessageComposeViewController.canSendText() == true {
let recipients:[String] = ["1500"]
let messageController = MFMessageComposeViewController()
messageController.messageComposeDelegate = self
messageController.recipients = recipients
messageController.body = "Your_text"
self.present(messageController, animated: true, completion: nil)
} else {
//handle text messaging not available
}
}

func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
controller.dismiss(animated: true, completion: nil)
}

关于swift3 - 使用 MFMessageComposeViewController 发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41343895/

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