我正在为我的公司开发一个小图像共享应用程序。一切都很好,除了一件事:当我将图像上传到服务器并将应用程序切换到背景时,图像的一部分已损坏(全灰色)。
只要应用程序处于活动状态,似乎图像数据就会正确发送。一旦我切换到后台,它似乎什么也不发送。
作为记录,我使用 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];
如果你们中的任何人有最小的想法,我会接受它!谢谢。