如何在twilio聊天中快速附加图像

时间:2018-08-03 05:54:33

标签: ios swift twilio twilio-programmable-chat

我尝试了此代码,但无法正常工作,请帮助我在twilio聊天中附加图片。

我从here获得此代码 一旦我从图库中获取图像并将其转换为数据,便将该数据附加到inputstream参数中,但是无法上传。

let messageOptions = TCHMessageOptions()
        let inputStream = InputStream(data: data)
        messageOptions.withMediaStream(inputStream,
                                       contentType: "image/jpeg",
                                       defaultFilename: "image.jpg",
                                       onStarted: {
                                        // Called when upload of media begins.
                                        self.activityIndicator.startAnimating()
                                        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")
            self.activityIndicator.stopAnimating()

        }

        self.generalChannel?.messages?.sendMessage(with: messageOptions,
                                                   completion: { (result, message) in
                                                    if !result.isSuccessful() {
                                                        print("Creation failed: \(String(describing: result.error))")
                                                    } else {
                                                        print("Creation successful")
                                                        self.tableView.reloadData()

                                                    }
        })
    }

0 个答案:

没有答案
相关问题