在后台上传时损坏的图像

我正在为我的公司开发一个小图像共享应用程序。 除了一件事之外,一切工作都很好:当我将图像上传到服务器,并将应用程序切换到背景时,图像的一部分已损坏(全灰)。

看起来,只要应用程序是活的,图像数据就会正确发送。 只要我切换到背景,它似乎没有发送任何东西。

为了logging,我使用ASIHttpRequest,shouldContinueWhenAppEntersBackground设置为YES,并且我正在从iOS 4.3运行应用程序到iOS 6.0。 我正在使用ARC。

我试图“保留”(通过强有力的参考)图像和数据,也没有。

以下是部分代码:

发送图像的Web服务

- (void)sendImage:(UIImage*)image forEmail:(NSString*)email { NSString* uploadImage = [NSString stringWithFormat:[self completeUrlForService:SEND_PHOTO], email]; NSURL* url = [NSURL URLWithString:[uploadImage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSLog(@"uploadImage %@", uploadImage); // setting that we will send a JSON object [self setRequestType:WebServiceWrapperTypePOSTRequest]; // when posting a picture, it could take more time... self.request.timeOutSeconds = 4*60; [self.request setShouldContinueWhenAppEntersBackground:YES]; // setting up the POST data [self addPostData:image forKey:@"fileContents"]; // start the request [self startRequestForUrl:url userInfo:[NSDictionary dictionaryWithObject:SEND_PHOTO forKey:URL_KEY]]; } 

ASIHttpRequest类的实际部分

 self.request = [ASIHTTPRequest requestWithURL:url]; [self.request setShouldContinueWhenAppEntersBackground:YES]; NSString* key = [[self.postDictionnary allKeys] objectAtIndex:0]; UIImage* value = [self.postDictionnary valueForKey:key]; __strong NSData* data = UIImageJPEGRepresentation(value, 1.0); if (!data) data = UIImagePNGRepresentation(value); [self.request appendPostData:data]; [self.request setPostLength:data.length]; [self.request setUserInfo:userInfo]; [self.request setDelegate:self]; [self.request startAsynchronous]; 

如果你们中的任何一个人有最小的想法,我会接受的! 谢谢。

最后,我决定使用不同的库(MKNetworkKit),而不是发送一个UIImage,我把磁盘上的图像保存到tmp文件夹,然后发送文件。 下载完成后,我只是删除磁盘上的图像。 它工作喜欢魅力:)