我正在尝试使用Twilio在可编程聊天中发送图像。我已经从UIImage创建了数据,并使用media选项将其发送。但是由于某种原因,我的应用程序在某些Twilio SDK文件中崩溃了。我要附加崩溃屏幕快照和我的代码。
func sendImage(image: UIImage) {
//get the JPEG data for this image
let data = image.jpegData(compressionQuality: 0.8)!
if let messages = TwilioHelper.sharedInstance.getcurrentChannel()?.messages {
let inputStream = InputStream(data: data)
let options = TCHMessageOptions().withMediaStream(inputStream,contentType: "image/jpeg",defaultFilename: "image.jpg",onStarted: {
print("Media upload started")
},onProgress: { (bytes) in
print("Media upload progress: \(bytes)")
}) { (mediaSid) in
print("Media upload completed")
}
print("sending photo")
messages.sendMessage(with: options) { result,msg in
if result.isSuccessful() {
print("success")
} else {
if let error = result.error {
print("error sending: \(error.localizedDescription) with \(error.code)")
} else {
print("error sending: Twilio service error")
}
}
}
} else {
print("can't get channel messages")
}
}