Я пытаюсь сделать фотографии в своем приложении и сохранить их по пути с двумя датами (чтобы указать, когда была сделана фотография).
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image;
image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); //save to photo album
NSString *pathString = [NSString stringWithFormat:@"Photos/%@/%@.png",timeStarted,[NSDate date]]; //create path
NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:pathString];
//write the files!
[UIImagePNGRepresentation(image) writeToFile:savePath atomically:YES];
}
Когда я проверяю папку @"Photos/%@",timeStarted
, она отображается как пустая. Что я делаю неправильно?
EDIT
Вот мой новый код для тестирования:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Create the image and save it to the photo album
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
//Create the directory and add the file name to it
NSString *fileName = @"Test.png";
NSString *directory = [NSHomeDirectory() stringByAppendingPathComponent:@"Photos"];
NSString *fullPath = [directory stringByAppendingPathComponent:fileName];
NSLog(@"Full path: %@", fullPath);
//Save "image" to the file path
[UIImagePNGRepresentation(image) writeToFile:fullPath atomically:YES];
//START CHECKING : Log to check if anything was saved
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSLog(@"Photos directory: %@", [fileMgr contentsOfDirectoryAtPath:directory error:&error]);
//END CHECKING
[camera dismissModalViewControllerAnimated:YES];
}
А мой NSLog
читает:
[640:707] Full path: /var/mobile/Applications/3EEDBD68-5496-458D-9EF0-062746847C83/Photos/Test.png
[640:707] Photos directory: (null)