使用UIActivityViewController未将多张图像保存在照片库中

Mr.*_*ean 5 uiimage ios uiactivityviewcontroller swift

我需要在照片库中保存多个图像,用户可以从应用程序库中多次选择图像,然后将它们保存在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
}
Run Code Online (Sandbox Code Playgroud)

Sea*_*ean 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"];
});
}
}];
}
Run Code Online (Sandbox Code Playgroud)