iPad: ImageIO: <ERROR> JPEGNot a JPEG file: starts with 0xff 0xd9 [closed]

ぐ巨炮叔叔 提交于 2019-12-24 11:07:17

问题


the error-message i quoted in question-title is driving me crazy on my iPad.

i am downloading some Jpeg-Files form HTTP-Servers, and using my code works fine on the iphone (iOS 5.0). On my iPad (4.3) it messages this error and the image cannot be displayed.

What makes me wonder is how i fixed it, which is not clear to me!

So i am Downloading the Jpeg via NSURLConnection (conn) and a NSMutableData (imageData):

conn = [[NSURLConnection alloc] 
       initWithRequest:[NSURLRequest requestWithURL:[camera getJpgUrl] 
                                        cachePolicy:NSURLRequestReloadIgnoringLocalCacheData 
                                    timeoutInterval:10] 
                       delegate:self 
                       startImmediately:YES];

if(conn && !imageData)
{
    imageData = [[NSMutableData data] retain];
}

the delegate-methods are :

1) getting more data

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [imageData appendData:data];
}

2) having all the data:

-(void)connectionDidFinishLoading:(NSURLConnection *)aConnection
{
    UIImage *img = [UIImage imageWithData:imageData];

    [imageData setLength:0];
    [conn release];
    conn = nil;

    if(img)
    {
        imageView.image=img;
    }
}

Hooray sais the iphone, welcome yells the image.

On the iPad however, i have to release the imageData-Object instead of settings its length to 0 when i restart that method initializing the NSUrlConnection. i restart it for image-updates etc.

So the code in iPad is (just to sum it up):

-(void)connectionDidFinishLoading:(NSURLConnection *)aConnection
{
    UIImage *img = [UIImage imageWithData:imageData];

    [imageData release];
    imagedata = [[NSMutableData data] retain];
    conn release];
    conn = nil;

    if(img)
    {
        imageView.image=img;
    }
}

So for now, the imageData handling in my code is a result of testing, so i could change it to have a move elegant handling. Thats not so important.

But what makes me wonder is, why does setLength:0 does what it should on ios5/iphone4, but not on ipad? i hope that i just messed up something, but here i really dont understand what is going on.

Any thoughts ?

Thank you!


回答1:


okay, the server hat some bugs :/



来源:https://stackoverflow.com/questions/8173382/ipad-imageio-error-jpegnot-a-jpeg-file-starts-with-0xff-0xd9

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