iPhone - Corrupt JPEG data for image received over HTTP

后端 未结 5 1734
我寻月下人不归
我寻月下人不归 2020-12-10 16:04

I\'m getting an image over HTTP, using NSURLConnection, as follows -

NSMutableData *receivedData;

- (void)getImage {
    self.receivedData = [[NSMutableDat         


        
5条回答
  •  孤城傲影
    2020-12-10 17:00

    Copying the NSData content using receivedData = [NSData dataWithBytes:receivedData.bytes length:receivedData.length] may be helpful too (and it's more efficient than saving to and reading from the disk).

    A possible reason for this is that the original receivedData object does not retain its content (e.g. when created using [NSData dataWithBytesNoCopy:length:]) and you try to read them after they are freed.

    This is likely when you encounter this problem on another thread from the thread that created the NSData object.

提交回复
热议问题