目前正在尝试打开附有图像的 MFMessageComposeViewController
,但我在旧代码中发现的 typeIdentifier
似乎不合适,我无法打开查找有关将图像附加到消息的任何文档,而不是将图像复制到粘贴板/剪贴板,然后让用户手动将其粘贴到消息中。
func sendMessageWith(imageData: Data) -> MFMessageComposeViewController? {
if MFMessageComposeViewController.canSendText() == true {
let composeVC = MFMessageComposeViewController()
composeVC.messageComposeDelegate = self
composeVC.addAttachmentData(imageData, typeIdentifier: kUTTypeJPEG, filename: "image.jpg")
print("OK")
return composeVC
}
print("Try Again")
return nil
}
最佳答案
您需要导入MobileCoreServices
框架:
import MobileCoreServices
其中包含 UTCoreTypes
header ,其中包含 kUTTypeJPEG
。
并且您必须将常量转换为 String
,因为它是一个 CFString
:
composeVC.addAttachmentData(
imageData,
typeIdentifier: kUTTypeJPEG as String,
filename: "image.jpg"
)
关于Swift 3 - 发送带有图像的消息 - 未确定的文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44164699/