twilio / conversations-ios

SPM releases

Home Page:https://www.twilio.com/docs/conversations/ios/changelog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Audio Message not working

aiyub007 opened this issue · comments

commented

I am trying to upload media using below code

let messageOptions = TCHMessageOptions()
        do {
            let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
            messageOptions.withMediaStream(inputStream,
                                           contentType: "audio/m4a",
                                           defaultFilename: "sound.m4a",
                                           onStarted: {
                                            
                                           },
                                           onProgress: { (bytes) in

                                           }) { (mediaSid) in
                self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
                    if result.resultCode == 200
                    {
                        self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
                    }
                }

I also tried different Mime type [contentType] . Media is there in data control just not going in started or on progress.
completion not working
no error got in the result

Thanks in advance

Hello, you should create options and then send message using these options. To solve your issue it should be enough to move 'sendMessage' from media upload completion.

commented

@Gray-Wind Thanks for response
we are already doing the process for the video it works fine.

As per your suggestion i tries modify it in completed :

let messageOptions = TCHMessageOptions()
       do {
           let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
           messageOptions.withMediaStream(inputStream, contentType: "audio/m4a", defaultFilename: "audio.m4a") {
               
           } onProgress: { (prg) in
               print(prg)
           } onCompleted: { (mediaSid) in
               self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
                   if result.resultCode == 200
                   {
                       self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
                   }
               }
           }


       }catch {
           print(error as Error)
       }

still the same problem.
control is not reaching to the completion not even on progress
Still checking the mime types

commented

It worked
Needed to call out side

{ (mediaSid) in
 }
self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
                    if result.resultCode == 200
                    {
                        self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
                    }

Basically TCHMessageOptions doesn't do anything except for telling sendMessage what to send.

let messageOptions = TCHMessageOptions()
        do {
            let inputStream = try InputStream(data: Data(contentsOf: recordingView.getFileURL()))
            messageOptions.withMediaStream(inputStream,
                                           contentType: "audio/m4a",
                                           defaultFilename: "sound.m4a",
                                           onStarted: {
                                            
                                           },
                                           onProgress: { (bytes) in

                                           }) { (mediaSid) in
                                               print("message with sent with sid \(mediaSid)")
                                           }
            self.currentConversationObj.sendMessage(with: messageOptions) { (result, msg) in
                if result.isSuccessful {
                    self.currentConversationObj.setAllMessagesReadWithCompletion { (res, count) in }
                }
            }
        }