0

I am using twilio chat SDK, in that I am doing store and retrieve the image. So to retrieve the image from twilio I am getting NSOutputStream, And I don't know that how to convert NSOutputStream to image. Please see the below code which provided by twilio and give me some suggestions.

chatCell.message = message.body;
if (message.hasMedia) {
    NSLog(@"mediaFilename: %@ (optional)", message.mediaFilename);
    NSLog(@"mediaSize: %lu", (unsigned long)message.mediaSize);
    // Set up output stream for media content
    NSString *tempFilename = [NSTemporaryDirectory() stringByAppendingPathComponent:message.mediaFilename ? @"file.dat" : message.mediaFilename];
    NSOutputStream *outputStream = [NSOutputStream outputStreamToFileAtPath:tempFilename append:NO];

    // Request the start of the download
    [message getMediaWithOutputStream:outputStream
                            onStarted:^{
                                // Called when download of media begins.
                            } onProgress:^(NSUInteger bytes) {
                                // Called as download progresses, with the current byte count.
                            } onCompleted:^(NSString * _Nonnull mediaSid) {
                                // Called when download is completed, with the new mediaSid if successful.
                                // Full failure details will be provided through the completion block below.
                            } completion:^(TCHResult * _Nonnull result) {
                                if (!result.isSuccessful) {
                                    NSLog(@"Download failed: %@", result.error);
                                } else {
                                    NSLog(@"Download successful");
                                    NSLog(@"%@",message.body);
                                }
                            }];
}   

I am not sure how to get an image after download complete successful. Please help me to fix this.

Thanks in advance.

Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
  • 1
    Check this? https://github.com/twilio/twilio-chat-demo-ios/blob/master/Demo-ObjC/DemoHelpers.m#L266 ? You get the image at `[UIImage imageWithContentsOfFile:finalFilename]`. – Larme Dec 30 '19 at 13:05
  • @Larme Thank You So So much man. You are a saviour :) – Mihir Oza Dec 30 '19 at 13:42

0 Answers0