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{
|
||||
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];
|
||||
}
|
||||
|
||||
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,44 +263,52 @@
|
|||
// 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(), ^{
|
||||
// save the url
|
||||
if (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"
|
||||
inManagedObjectContext:[SharedAppDelegate managedObjectContext]];
|
||||
sync.filePath = photo.syncedUrl;
|
||||
sync.status = kSyncedStatusTypeUploaded;
|
||||
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.
|
||||
// in the case of edited images via Aviary, we don't save it.
|
||||
Synced *sync = [NSEntityDescription insertNewObjectForEntityForName:@"Synced"
|
||||
inManagedObjectContext:[SharedAppDelegate managedObjectContext]];
|
||||
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.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
|
||||
// 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,21 +368,23 @@
|
|||
}
|
||||
});
|
||||
}@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]) {
|
||||
|
||||
|
||||
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 you’d like to download your friend’s 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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue