How to get image from NSOutputStream in Objective-C

醉酒当歌 提交于 2020-01-06 04:46:04

问题


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.

来源:https://stackoverflow.com/questions/59526513/how-to-get-image-from-nsoutputstream-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!