gpt4 book ai didi

ios - 如何在 MFMessageComposeViewController 中启用摄像头?

转载 作者:可可西里 更新时间:2023-11-01 02:01:39 24 4
gpt4 key购买 nike

我正在开发一个带有按钮的 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 应用程序等的按钮在那里,但它们被禁用且无法按下。我如何启用这些按钮(特别是相机)以允许我的用户将图像附加到使用该应用程序撰写的消息中?

有问题的按钮: The Buttons in Question

编辑:感谢阿卜杜拉哈德的建议。我修改了他的回复以允许多个收件人并包含邮件正文。我还更新了它以删除已弃用的 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/

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