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.
[UIImage imageWithContentsOfFile:finalFilename]
. – Tolidine