使用UIActivityViewController无法将多个图像保存在照片库中

时间:2018-08-17 12:22:03

标签: ios swift uiimage uiactivityviewcontroller

我需要在照片库中保存多个图像,用户可以从应用程序库中多次选择图像,然后可以将它们保存在iPhone照片库中。我正在为此显示UIActivityViewController

假设用户选择了10张或更多图片,然后选择将其保存到照片库中,则仅保存7-8张图片。

我有什么方法可以将照片阵列保存在照片库中而不会出现任何故障?

谢谢

let images = Generic.fetchImagesFromMediaFiles(self.selectedMediaObj) // to fetch selected images

let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil)
self.present(activityViewController, animated: true, completion: nil);

if let popoverPresentationController = activityViewController.popoverPresentationController {
    popoverPresentationController.sourceView = self.shareAllView
}

2 个答案:

答案 0 :(得分:2)

iOS系统将照片保存到相册使用单线程,一个接一个地做。 如果您想同时保存更多照片,则可能会丢失一些数据。

-(void)saveBtn
{
[SSGOTools againRequestPhotoWithblock:^(BOOL isAgree) {
if (isAgree) {

self.listOfImages = [NSMutableArray new];
int photoNum ;
photoNum = (int)_photoArray.count;
if (_photoArray.count > 9) {
photoNum = 9;
}
for (int i = 0; i < photoNum; i++) {
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:_photoArray[i]]];
UIImage *myImage = [UIImage imageWithData:data];
//[self.listOfImages addObject:myImage];
[self loadImageFinished:myImage];

}
}
}];
}

- (void)loadImageFinished:(UIImage *)image
{
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{

//write photo save to album

[PHAssetChangeRequest creationRequestForAssetFromImage:image];

} completionHandler:^(BOOL success, NSError * _Nullable error) {

NSLog(@"success = %d, error = %@", success, error);
if(success){
dispatch_async(dispatch_get_main_queue(), ^{
[SSGOTools showInfoPopHint:@"Success"];
});
}
}];
}

答案 1 :(得分:2)

您将需要在此处使用完成框来确保所有图像都已保存。尝试此操作:

$('#list').click(function(event){
    ...
    $('#grid-view').hide();
    $('#list-view').show();
});

$('#grid').click(function(event){
   ...
    $('#grid-view').show();
    $('#list-view').hide();
});