memory leak
This commit is contained in:
parent
f18d52411c
commit
faf70ac873
4 changed files with 84 additions and 63 deletions
|
@ -106,7 +106,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void) copyImages{
|
-(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 you’d like to download your friend’s album to your NAS",@"Message to Please confirm you’d like to download your friend’s photo to your NAS") delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel",@"") otherButtonTitles:NSLocalizedString(@"Copy",@""),nil];
|
||||||
[alert show];
|
[alert show];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +115,23 @@
|
||||||
#ifdef DEVELOPMENT_ENABLED
|
#ifdef DEVELOPMENT_ENABLED
|
||||||
NSLog(@"Add all images in the database");
|
NSLog(@"Add all images in the database");
|
||||||
#endif
|
#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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +223,7 @@
|
||||||
|
|
||||||
[browser setCurrentPhotoIndex:indexPath.row];
|
[browser setCurrentPhotoIndex:indexPath.row];
|
||||||
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:browser];
|
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:browser];
|
||||||
|
|
||||||
// Present
|
// Present
|
||||||
[self presentViewController:nav animated:NO completion:nil];
|
[self presentViewController:nav animated:NO completion:nil];
|
||||||
}
|
}
|
||||||
|
|
|
@ -230,9 +230,6 @@
|
||||||
for (Timeline *photo in waitings){
|
for (Timeline *photo in waitings){
|
||||||
photo.status = kUploadStatusTypeUploading;
|
photo.status = kUploadStatusTypeUploading;
|
||||||
|
|
||||||
// create a delegate
|
|
||||||
JobUploaderDelegate *delegate = [[JobUploaderDelegate alloc] initWithPhoto:photo size:[NSNumber numberWithInteger:0]];
|
|
||||||
|
|
||||||
NSDictionary *dictionary = nil;
|
NSDictionary *dictionary = nil;
|
||||||
@try {
|
@try {
|
||||||
dictionary = [photo toDictionary];
|
dictionary = [photo toDictionary];
|
||||||
|
@ -253,11 +250,6 @@
|
||||||
// prepare the data to upload
|
// prepare the data to upload
|
||||||
NSString *filename = photo.fileName;
|
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
|
// create the service, check photo exists and send the request
|
||||||
WebService *service = [[WebService alloc] init];
|
WebService *service = [[WebService alloc] init];
|
||||||
|
|
||||||
|
@ -271,44 +263,52 @@
|
||||||
// copy
|
// copy
|
||||||
response= [service copyPictureWithUrl:photo.photoUrl];
|
response= [service copyPictureWithUrl:photo.photoUrl];
|
||||||
}else{
|
}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];
|
response= [service uploadPicture:data metadata:dictionary fileName:filename delegate:delegate];
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEVELOPMENT_ENABLED
|
#ifdef DEVELOPMENT_ENABLED
|
||||||
NSLog(@"Photo uploaded correctly");
|
NSLog(@"Photo uploaded correctly");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
// save the url
|
if (![photo.copyFromFriend boolValue]){
|
||||||
if (photo.syncedUrl){
|
// save the url
|
||||||
// add to the sync list, with that we don't need to show photos already uploaded.
|
if (photo.syncedUrl){
|
||||||
// in the case of edited images via Aviary, we don't save it.
|
// add to the sync list, with that we don't need to show photos already uploaded.
|
||||||
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
|
// in the case of edited images via Aviary, we don't save it.
|
||||||
inManagedObjectContext:[SharedAppDelegate managedObjectContext]];
|
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
|
||||||
sync.filePath = photo.syncedUrl;
|
inManagedObjectContext:[SharedAppDelegate managedObjectContext]];
|
||||||
sync.status = kSyncedStatusTypeUploaded;
|
sync.filePath = photo.syncedUrl;
|
||||||
|
sync.status = kSyncedStatusTypeUploaded;
|
||||||
|
|
||||||
|
// used to say which user uploaded this image
|
||||||
|
sync.userUrl = [SharedAppDelegate userHost];
|
||||||
|
}
|
||||||
|
|
||||||
// used to say which user uploaded this image
|
|
||||||
sync.userUrl = [SharedAppDelegate userHost];
|
photo.photoUploadResponse = [NSDictionarySerializer nsDictionaryToNSData:[response objectForKey:@"result"]];
|
||||||
|
|
||||||
|
// delete local file
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
NSError *error;
|
||||||
|
BOOL fileExists = [fileManager fileExistsAtPath:photo.photoDataTempUrl];
|
||||||
|
#ifdef DEVELOPMENT_ENABLED
|
||||||
|
NSLog(@"Path to file: %@", photo.photoDataTempUrl);
|
||||||
|
NSLog(@"File exists: %d", fileExists);
|
||||||
|
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:photo.photoDataTempUrl]);
|
||||||
|
#endif
|
||||||
|
if (fileExists)
|
||||||
|
{
|
||||||
|
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
|
||||||
|
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
photo.status = kUploadStatusTypeUploadFinished;
|
photo.status = kUploadStatusTypeUploadFinished;
|
||||||
photo.photoUploadResponse = [NSDictionarySerializer nsDictionaryToNSData:[response objectForKey:@"result"]];
|
|
||||||
|
|
||||||
// delete local file
|
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
||||||
NSError *error;
|
|
||||||
BOOL fileExists = [fileManager fileExistsAtPath:photo.photoDataTempUrl];
|
|
||||||
#ifdef DEVELOPMENT_ENABLED
|
|
||||||
NSLog(@"Path to file: %@", photo.photoDataTempUrl);
|
|
||||||
NSLog(@"File exists: %d", fileExists);
|
|
||||||
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:photo.photoDataTempUrl]);
|
|
||||||
#endif
|
|
||||||
if (fileExists)
|
|
||||||
{
|
|
||||||
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
|
|
||||||
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if there is more files to upload
|
// check if there is more files to upload
|
||||||
// if not, refresh the Home page
|
// if not, refresh the Home page
|
||||||
|
@ -320,16 +320,18 @@
|
||||||
// refresh profile details
|
// refresh profile details
|
||||||
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationProfileRefresh object:nil userInfo:nil];
|
[[NSNotificationCenter defaultCenter] postNotificationName:kNotificationProfileRefresh object:nil userInfo:nil];
|
||||||
|
|
||||||
|
/*
|
||||||
// also lets save the Managed Context
|
// also lets save the Managed Context
|
||||||
NSError *saveError = nil;
|
NSError *saveError = nil;
|
||||||
if (![[SharedAppDelegate managedObjectContext] save:&saveError]){
|
if (![[SharedAppDelegate managedObjectContext] save:&saveError]){
|
||||||
NSLog(@"Error to save context = %@",[saveError localizedDescription]);
|
NSLog(@"Error to save context = %@",[saveError localizedDescription]);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}@catch (NSException* e) {
|
}@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
|
// if it fails for any reason, set status FAILED in the main thread
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
@ -338,7 +340,7 @@
|
||||||
[[e description] hasPrefix:@"409"]){
|
[[e description] hasPrefix:@"409"]){
|
||||||
|
|
||||||
// this photo is already uploaded
|
// 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.
|
// 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.
|
// in the case of edited images via Aviary, we don't save it.
|
||||||
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
|
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
|
||||||
|
@ -366,21 +368,23 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}@finally{
|
}@finally{
|
||||||
// delete local file
|
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
||||||
NSError *error;
|
|
||||||
BOOL fileExists = [fileManager fileExistsAtPath:photo.photoDataTempUrl];
|
|
||||||
#ifdef DEVELOPMENT_ENABLED
|
|
||||||
NSLog(@"Path to file: %@", photo.photoDataTempUrl);
|
|
||||||
NSLog(@"File exists: %d", fileExists);
|
|
||||||
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:photo.photoDataTempUrl]);
|
|
||||||
#endif
|
|
||||||
if (fileExists)
|
|
||||||
{
|
|
||||||
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
|
|
||||||
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (![photo.copyFromFriend boolValue]){
|
||||||
|
// delete local file
|
||||||
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
NSError *error;
|
||||||
|
BOOL fileExists = [fileManager fileExistsAtPath:photo.photoDataTempUrl];
|
||||||
|
#ifdef DEVELOPMENT_ENABLED
|
||||||
|
NSLog(@"Path to file: %@", photo.photoDataTempUrl);
|
||||||
|
NSLog(@"File exists: %d", fileExists);
|
||||||
|
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:photo.photoDataTempUrl]);
|
||||||
|
#endif
|
||||||
|
if (fileExists)
|
||||||
|
{
|
||||||
|
BOOL success = [fileManager removeItemAtPath:photo.photoDataTempUrl error:&error];
|
||||||
|
if (!success) NSLog(@"Error: %@", [error localizedDescription]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1228,8 +1228,8 @@
|
||||||
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
|
if ([self numberOfPhotos] > 0 && [photo underlyingImage]) {
|
||||||
|
|
||||||
|
|
||||||
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Copy to your Trovebox"
|
UIAlertView *message = [[UIAlertView alloc] initWithTitle:nil
|
||||||
message:@"Please confirm download your friend's photo to you account."
|
message:@"Please confirm you’d like to download your friend’s photo to your NAS."
|
||||||
delegate:self
|
delegate:self
|
||||||
cancelButtonTitle:@"Cancel"
|
cancelButtonTitle:@"Cancel"
|
||||||
otherButtonTitles:@"Yes",nil];
|
otherButtonTitles:@"Yes",nil];
|
||||||
|
@ -1246,13 +1246,6 @@
|
||||||
|
|
||||||
PhotoFriendUploader *upload = [[PhotoFriendUploader alloc]init];
|
PhotoFriendUploader *upload = [[PhotoFriendUploader alloc]init];
|
||||||
[upload loadDataAndSaveEntityUrl:photo.url];
|
[upload loadDataAndSaveEntityUrl:photo.url];
|
||||||
|
|
||||||
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Copying"
|
|
||||||
message:@""
|
|
||||||
delegate:nil
|
|
||||||
cancelButtonTitle:@"OK"
|
|
||||||
otherButtonTitles:nil];
|
|
||||||
[message show];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,7 +208,14 @@
|
||||||
|
|
||||||
// set the parameter already added in the signature
|
// set the parameter already added in the signature
|
||||||
[asiRequest addPostValue:photoUrl forKey:@"photo"];
|
[asiRequest addPostValue:photoUrl forKey:@"photo"];
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef DEVELOPMENT_ENABLED
|
||||||
|
NSLog(@"Request to be sent = [%@]",urlString);
|
||||||
|
NSLog(@"PhotoUrl = [%@]",photoUrl);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// timeout 4 minutes. TODO. Needs improvements.
|
// timeout 4 minutes. TODO. Needs improvements.
|
||||||
[asiRequest setTimeOutSeconds:240];
|
[asiRequest setTimeOutSeconds:240];
|
||||||
[asiRequest startSynchronous];
|
[asiRequest startSynchronous];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue