Ios 使用twilio可编程聊天api发送PDF/文本

Ios 使用twilio可编程聊天api发送PDF/文本,ios,swift,twilio,Ios,Swift,Twilio,我正在使用适用于iOS的Twilio可编程聊天SDK创建聊天应用程序。我使用SDK发送了图像和文本,效果很好 但是,当我尝试使用内容类型application/pdf或text发送pdf时,会抛出以下错误 Error Domain=signal.sdk.domain.error Code=101 "" UserInfo={kTCHErrorMsgKey=, NSLocalizedDescription=} 下面是我用来发送pdf的代码 do {

我正在使用适用于iOS的Twilio可编程聊天SDK创建聊天应用程序。我使用SDK发送了图像和文本,效果很好

但是,当我尝试使用内容类型application/pdf或text发送pdf时,会抛出以下错误

Error Domain=signal.sdk.domain.error Code=101 "" UserInfo={kTCHErrorMsgKey=, NSLocalizedDescription=}
下面是我用来发送pdf的代码

        do {
                let fileData = try Data(contentsOf: pickedDocUrl)
                // Prepare the upload stream and parameters
                let messageOptions = TCHMessageOptions()
                let inputStream = InputStream(data: fileData)
                messageOptions.withMediaStream(inputStream,
                                               contentType: "application/pdf",
                                               defaultFilename: "\(pickedDocUrl.lastPathComponent.components(separatedBy: ".")[0]).pdf",
                    onStarted: {
                        // Called when upload of media begins.
                        print("Media upload started")
                },
                    onProgress: { (bytes) in
                        // Called as upload progresses, with the current byte count.
                        print("Media upload progress: \(bytes)")
                }) { (mediaSid) in
                    // Called when upload is completed, with the new mediaSid if successful.
                    // Full failure details will be provided through sendMessage's completion.
                    print("Media upload completed")
                }

                // Trigger the sending of the message.
                self.generalChannel?.messages?.sendMessage(with: messageOptions,
                                                           completion: { (result, message) in
                                                            self.pickedDocUrl = nil

                                                            if !result.isSuccessful() {
                                                                print("Creation failed: \(String(describing: result.error))")
                                                            } else {
                                                                print("Creation successful")
                                                            }
                })
            } catch {
                print("Unable to load data: \(error)")
            }

我有同样的问题..通过从文件中添加MIME或内容类型修复了它

let mimeType =  mimeTypeForPath(path: fileUrl.path)

    func mimeTypeForPath(path: String) -> String {
        let url = NSURL(fileURLWithPath: path)
        let pathExtension = url.pathExtension
        if let uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, pathExtension! as NSString, nil)?.takeRetainedValue() {
            if let mimetype = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType)?.takeRetainedValue() {
                return mimetype as String
            }
        }
        return "application/octet-stream";
    }