Да, вы можете сохранить изображения в каталоге документа и сохранить имена файлов изображений в массив после этого извлекает эти изображения из документа. реж. точно так же как
// For error information
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/YOUR_IMG_FOLDER"];
if (![fileMgr fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
//Get the current date and time and set as image name
NSDate *now = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd_HH-mm-ss";
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *gmtTime = [dateFormatter stringFromDate:now];
NSLog(@"The Current Time is :%@", gmtTime);
NSData *imageData = UIImageJPEGRepresentation(_postImage, 0.5); // _postImage is your image file and you can use JPEG representation or PNG as your wish
int imgSize = imageData.length;
////NSLog(@"SIZE OF IMAGE: %.2f Kb", (float)imgSize/1024);
NSString *imgfileName = [NSString stringWithFormat:@"%@%@", gmtTime, @".jpg"];
// File we want to create in the documents directory
NSString *imgfilePath= [dataPath stringByAppendingPathComponent:imgfileName];
// Write the file
[imageData writeToFile:imgfilePath atomically:YES];
**// Keep your Image file name into an mutable array here OR you can saved the array in a UserDefaults**
Затем извлекайте из документа. реж. из итерации массива.
//Get image file from sand box using file name and file path
NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"YOUR_IMG_FOLDER"];
stringPath = [stringPath stringByAppendingPathComponent:imgFile]; // imgFile to get from your array, where you saved those image file names
UIImage *image = [UIImage imageWithContentsOfFile:stringPath];
спасибо ... счастливый код.
Просто сохраните файл в каталоге с уникальным именем, магазин, что уникальное имя в массив и извлечение изображения из каталога, показать в вашем столе. Если вы хотите ответ, тогда я отправлю его –
Если вы хотите сохранить изображения в библиотеке фотографий по умолчанию, воспользуйтесь .. https://stackoverflow.com/a/44328085/5315917 –