作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在开发一个带有按钮的 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 应用程序等的按钮在那里,但它们被禁用且无法按下。我如何启用这些按钮(特别是相机)以允许我的用户将图像附加到使用该应用程序撰写的消息中?
编辑:感谢阿卜杜拉哈德的建议。我修改了他的回复以允许多个收件人并包含邮件正文。我还更新了它以删除已弃用的 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 会显示按钮而不启用它们?
最佳答案
不要使用 MFMessageComposeViewController 使用 UIApplication.shared.openURL(url!) 但这会使用户离开应用程序
var phoneToCall: String = "sms: +201016588557"
var phoneToCallEncoded = phoneToCall.addingPercentEscapes(using: String.Encoding.ascii)
var url = URL(string: phoneToCallEncoded)
UIApplication.shared.openURL(url!)
关于ios - 如何在 MFMessageComposeViewController 中启用摄像头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45823583/
我是一名优秀的程序员,十分优秀!