【发布时间】:2017-08-22 17:21:24
【问题描述】:
我正在开发一个带有按钮的 iOS 应用程序,用于使用 SMS/iMessage 报告问题。我正在使用 MFMessageComposeViewController 使用以下代码(Swift 3)呈现消息组合界面:
if(MFMessageComposeViewController.canSendText()){
let controller = MFMessageComposeViewController()
controller.messageComposeDelegate = self
controller.body = "Example Message"
controller.recipients = ["2345678901"]
self.present(controller, animated: true, completion: nil)
}
我还实现了 MFMessageComposeViewControllerDelegate 函数以正确关闭。标准短信/iMessage 发送成功,但用户没有附加图像的选项。相机、iMessage 应用程序等按钮在那里,但它们被禁用且无法按下。如何启用这些按钮(特别是相机)以允许我的用户将图像附加到使用应用程序编写的消息中?
编辑:
感谢 Abdelahad 的建议。我修改了他的回复以允许多个收件人并包含消息正文。我还对其进行了更新以删除已弃用的 addingPercentEscapes(using: ) 方法。
这是一个使用 url 打开消息应用程序的解决方案。注意:这会使用户退出应用程序。
let recipients = "2345678901,3456789012" //Phone Numbers
let messageBody = "This is a test"
let sms: String = "sms://open?addresses=\(recipients)&body=\(messageBody)"
let smsEncoded = sms.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed)
let url = URL(string: smsEncoded!)
UIApplication.shared.openURL(url!)
但我仍然想要一个不会让用户退出应用程序的解决方案。这可能吗?为什么 MFMessageComposeViewController 会显示按钮而不启用它们?
【问题讨论】:
-
你有想过这个吗?我现在遇到了同样的问题
-
不,我没有。这似乎是 MFMessageComposeViewControllerDelegate 中的一个错误
-
这绝对是一个错误,面临同样的问题。目前唯一合适的解决方案是使用 url。
-
2020年了,我觉得这个问题还是存在的。我一直在寻找解决方案,到目前为止,我一无所获。我的理解是相机按钮一直工作到 iOS 10 之后才停止。我们现在升级到 iOS13 并且不工作的按钮仍然存在。