Reputation:
I am storing my image object in the NSMutableArray but after 11 image i get the memory warning, is there any more efficient way than this without storing image physically.
I just want to hold that object in my app until user click the button and at time i am storing the images.
UPDATE
I am storing images internally. But now when i upload this all image(which is 22) on server in one request app crashes With message "App crashes because of Memory Pressure"
-(void) uploadImages:(NSArray* )imageAry
{
__block NSString * tmpdocumentType =documentType;
dispatch_queue_t backgroundQueue = dispatch_queue_create("com.mycompany.myqueue", 0);
dispatch_async(backgroundQueue, ^{
tmpdocumentType = [tmpdocumentType stringByAddingPercentEscapesUsingEncoding:
NSASCIIStringEncoding];
NSString *urlString = [NSString stringWithFormat:@"http://myserver.com/wsname.aspx"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:3600.f];
[request setHTTPMethod:@"POST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
NSMutableData *body = [NSMutableData data];
for (int i=0; i<imageAry.count; i++) {
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"images[]\"; filename=\"test%i.png\"\r\n",i] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
UIImage * image = [self loadImage:[imageAry objectAtIndex:i]];
[body appendData:UIImageJPEGRepresentation(image, 1.0)];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
image = nil;
}
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSError * error = Nil;
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
if([returnString rangeOfString:@"Success"].location!=NSNotFound){
}else{
}
});
});
}
Upvotes: 0
Views: 309
Reputation: 14063
Write the images to disk and store a file path to the image in the array.
Upvotes: 1