Swift 3 - 发送带有图像的消息 - 未确定的文字

标签 swift image message mfmessagecomposeviewcontroller

目前正在尝试打开附有图像的 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/

相关文章:

javascript - 仅当图像更改时从目录重新加载图像

ios - Swift 2 通过 Segue 从 UIcollectionview (indexpath.row) 传递数据

swift - "ExpressibleByArrayLiteral"可以通用吗?

image - iPhone中的route-me图像叠加

events - 如何使用RESTful Web服务创建异步通知系统?

c - 消息队列不会读取枚举类型的消息

php - 使用消息重定向到另一个页面

ios - 如何在 Swift 4 CoreData 中设置合并策略

ios - 隐藏带有约束和动画的 View

image - 适用于小图像 (80x80) 的最佳 CNN 架构?