memory leak

This commit is contained in:
Patrick Santana 2014-05-06 20:58:22 -03:00
parent f18d52411c
commit faf70ac873
4 changed files with 84 additions and 63 deletions

View file

@ -106,7 +106,7 @@
}
-(void) copyImages{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Are you sure you want to download this Friend's album to your account?",@"Message to confirm if user really wants copy buddy's photos") message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",@"") otherButtonTitles:NSLocalizedString(@"Copy",@""),nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:NSLocalizedString(@"Please confirm youd like to download your friends album to your NAS",@"Message to Please confirm youd like to download your friends photo to your NAS") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",@"") otherButtonTitles:NSLocalizedString(@"Copy",@""),nil];
[alert show];
}
@ -115,6 +115,23 @@
#ifdef DEVELOPMENT_ENABLED
NSLog(@"Add all images in the database");
#endif
// limit to max 20;
int i = 0;
for ( MWPhoto *photo in self.photos){
if (i <20){
PhotoFriendUploader *upload = [[PhotoFriendUploader alloc]init];
[upload loadDataAndSaveEntityUrl:photo.url];
i++;
}else{
break;
}
}
// also lets save the Managed Context
NSError *saveError = nil;
if (![[SharedAppDelegate managedObjectContext] save:&saveError]){
NSLog(@"Error to save context = %@",[saveError localizedDescription]);
}
}
}

View file

@ -230,9 +230,6 @@
for (Timeline *photo in waitings){
photo.status = kUploadStatusTypeUploading;
// create a delegate
JobUploaderDelegate *delegate = [[JobUploaderDelegate alloc] initWithPhoto:photo size:[NSNumber numberWithInteger:0]];
NSDictionary *dictionary = nil;
@try {
dictionary = [photo toDictionary];
@ -253,11 +250,6 @@
// prepare the data to upload
NSString *filename = photo.fileName;
if (![photo.copyFromFriend boolValue]){
// on upload, not copying
// set size
delegate.totalSize = [NSNumber numberWithInteger:data.length];
}
// create the service, check photo exists and send the request
WebService *service = [[WebService alloc] init];
@ -271,14 +263,19 @@
// copy
response= [service copyPictureWithUrl:photo.photoUrl];
}else{
// create a delegate
JobUploaderDelegate *delegate = [[JobUploaderDelegate alloc] initWithPhoto:photo size:[NSNumber numberWithInteger:0]];
// set size
delegate.totalSize = [NSNumber numberWithInteger:data.length];
response= [service uploadPicture:data metadata:dictionary fileName:filename delegate:delegate];
}
#ifdef DEVELOPMENT_ENABLED
NSLog(@"Photo uploaded correctly");
#endif
dispatch_async(dispatch_get_main_queue(), ^{
if (![photo.copyFromFriend boolValue]){
// save the url
if (photo.syncedUrl){
// add to the sync list, with that we don't need to show photos already uploaded.
@ -292,7 +289,7 @@
sync.userUrl = [SharedAppDelegate userHost];
}
photo.status = kUploadStatusTypeUploadFinished;
photo.photoUploadResponse = [NSDictionarySerializer nsDictionaryToNSData:[response objectForKey:@"result"]];
// delete local file
@ -309,6 +306,9 @@
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
}
}
photo.status = kUploadStatusTypeUploadFinished;
// check if there is more files to upload
// if not, refresh the Home page
@ -320,16 +320,18 @@
// refresh profile details
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationProfileRefresh object:nil userInfo:nil];
/*
// also lets save the Managed Context
NSError *saveError = nil;
if (![[SharedAppDelegate managedObjectContext] save:&saveError]){
NSLog(@"Error to save context = %@",[saveError localizedDescription]);
}
*/
}
});
}
}@catch (NSException* e) {
NSLog(@"Error to upload image:%@", [e description]);
NSLog(@"Error Sync to upload image: %@", [e description]);
// if it fails for any reason, set status FAILED in the main thread
dispatch_async(dispatch_get_main_queue(), ^{
@ -338,7 +340,7 @@
[[e description] hasPrefix:@"409"]){
// this photo is already uploaded
if (photo.syncedUrl){
if (![photo.copyFromFriend boolValue] && photo.syncedUrl){
// add to the sync list, with that we don't need to show photos already uploaded.
// in the case of edited images via Aviary, we don't save it.
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
@ -366,6 +368,8 @@
}
});
}@finally{
if (![photo.copyFromFriend boolValue]){
// delete local file
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
@ -380,7 +384,7 @@
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
}
}
}
});
}

View file

@ -1228,8 +1228,8 @@
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Copy to your Trovebox"
message:@"Please confirm download your friend's photo to you account."
UIAlertView *message = [[UIAlertView alloc] initWithTitle:nil
message:@"Please confirm youd like to download your friends photo to your NAS."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Yes",nil];
@ -1246,13 +1246,6 @@
PhotoFriendUploader *upload = [[PhotoFriendUploader alloc]init];
[upload loadDataAndSaveEntityUrl:photo.url];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Copying"
message:@""
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
}
}

View file

@ -209,6 +209,13 @@
// set the parameter already added in the signature
[asiRequest addPostValue:photoUrl forKey:@"photo"];
#ifdef DEVELOPMENT_ENABLED
NSLog(@"Request to be sent = [%@]",urlString);
NSLog(@"PhotoUrl = [%@]",photoUrl);
#endif
// timeout 4 minutes. TODO. Needs improvements.
[asiRequest setTimeOutSeconds:240];
[asiRequest startSynchronous];