I am working on upload images application which seems working fine for me. I am uploading 100 images. and when i run this process 4-5 times application crashes out.
This seems to me memory usage issue.. How to reduce that memory. I don't want to my application get crashed.
btn_Cancel.userInteractionEnabled=NO;
btn_Share.userInteractionEnabled=NO;
btn_Back.userInteractionEnabled=NO;
btn_BackTransp.userInteractionEnabled=NO;
btn_BareCode.userInteractionEnabled=NO;
[self integratedLoaderView];
NSURL *url=[NSURL URLWithString:@"http:/apiurl /"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
NSString *str_EstimateNumber=[NSString stringWithFormat:@"%@",txtFld_FolderName.text];
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
formatter.dateFormat=@"yyyy-MM-dd";
string=[formatter stringFromDate:[NSDate date]];
NSString *str_time;
formatter.dateFormat=@"hh.mm.ss a";
str_time=[formatter stringFromDate:[NSDate date]];
NSString *str_AppendString=[NSString stringWithFormat:@"%@ at %@",string,str_time];
NSInteger str_Counter=[[NSString stringWithFormat:@"%lu",(unsigned long)[delegate.ary_ImageData count]] integerValue];
NSString *str_Value=[NSString stringWithFormat:@"%ld",(long)str_Counter];
NSString *str_Username=[NSString stringWithFormat:@"%@/Images",txtFld_SelectedFTP.text];
abc=0;
for (int i=0;i<[ary_Tosend count]; i++)
{
sleep(0.6);
abc++;
if ([str_ConnectionStatus isEqualToString:@"WiFi"])
{
}
if ([str_ConnectionStatus isEqualToString:@"Cellular"])
{
}
if ([str_ConnectionStatus isEqualToString:@"No Connection"])
{
btn_Cancel.userInteractionEnabled=YES;
btn_Share.userInteractionEnabled=YES;
btn_Back.userInteractionEnabled=YES;
btn_BackTransp.userInteractionEnabled=YES;
btn_BareCode.userInteractionEnabled=YES;
NSString *str_Total=[NSString stringWithFormat:@"%lu",(unsigned long)[ary_Tosend count]];
NSString *str_Saved=[NSString stringWithFormat:@"%lu",(unsigned long)[delegate.ary_ImageData count]];
NSInteger total_Count=[str_Total integerValue]-[str_Saved integerValue];
[self saveInDBWhenConnectionLost:total_Count];
[self ShowAlertForCheckInternetConnection];
return ;
}
if ([str_ConnectionStatus isEqualToString:@""])
{
btn_Cancel.userInteractionEnabled=YES;
btn_Share.userInteractionEnabled=YES;
btn_Back.userInteractionEnabled=YES;
btn_BackTransp.userInteractionEnabled=YES;
btn_BareCode.userInteractionEnabled=YES;
NSString *str_Total=[NSString stringWithFormat:@"%lu",(unsigned long)[ary_Tosend count]];
NSString *str_Saved=[NSString stringWithFormat:@"%lu",(unsigned long)[delegate.ary_ImageData count]];
NSInteger total_Count=[str_Total integerValue]-[str_Saved integerValue];
[self saveInDBWhenConnectionLost:total_Count];
[self ShowAlertForCheckInternetConnection];
return ;
}
NSString *str_fileName;
str_fileName=[NSString stringWithFormat:@"%@_%@ %i.jpg",str_EstimateNumber,str_AppendString,abc];
NSDictionary *params=nil;
NSData *imageToUpload=UIImageJPEGRepresentation([ary_Tosend objectAtIndex:i],0.25);
NSString *encodedString=[NSString stringWithFormat:@"%@",[imageToUpload base64Encoding]];
params= @{
@"categoryName" :txtFld_Category.text,
@"folderName" :txtFld_FolderName.text,
@"fileName" :str_fileName,
@"userName" :str_Username,
@"postedFile" :encodedString,
@"accessToken" :@"Q)4%v59!@lyr"
};
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
httpClient.parameterEncoding = AFFormURLParameterEncoding;
[httpClient registerHTTPOperationClass:[AFJSONRequestOperation class]];
[httpClient setDefaultHeader:@"Accept" value:@"application/json"];
NSMutableURLRequest *request=[httpClient requestWithMethod:@"POST"
path:@"UploadImages/upload"
parameters:params];
NSURLResponse* response=nil;
NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
if(data.length)
{
NSString *responseString=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *error = nil;
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if(responseString && responseString.length)
{
[delegate.ary_GetUploadedCount addObject:JSON];
[self responseUpload:JSON];
dispatch_async(dispatch_get_main_queue(),
^{
if(i < delegate.ary_ImageData. count)
{
[delegate.ary_ImageData removeObjectAtIndex:i];
[delegate.ary_TotalImages removeObjectAtIndex:i];
[ary_DataToConvert removeObjectAtIndex:i];
[ary_DataToConvert1 removeObjectAtIndex:i];
NSUserDefaults *default_AllImg=[NSUserDefaults standardUserDefaults];
[default_AllImg setValue:ary_DataToConvert forKey:@"ImageDetail"];
[default_AllImg synchronize];
NSUserDefaults *default_AllImg1=[NSUserDefaults standardUserDefaults];
[default_AllImg1 setValue:ary_DataToConvert1 forKey:@"ImageData"];
[default_AllImg1 synchronize];
}
});
}
}
}
});
Please tell me.
Aucun commentaire:
Enregistrer un commentaire