From 0ea1059f26b4e5522d94a819aef58315c76c7f1b Mon Sep 17 00:00:00 2001 From: Rafael Rocha Date: Wed, 28 Mar 2018 15:43:09 -0300 Subject: [PATCH] taking photo from camera returns PHAsset if shouldReturnImageForSingleSelection == NO --- .../Public/YMSPhotoPickerViewController.m | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m b/YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m index dba6a9c..d87f6e1 100644 --- a/YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m +++ b/YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m @@ -409,17 +409,18 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking if (![image isKindOfClass:[UIImage class]]) { return; } + + __block NSString *newAssetLocalIdentifier; // Save the image to Photo Album [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetCollection *collection = self.currentCollectionItem[@"collection"]; - if (collection.assetCollectionType == PHAssetCollectionTypeSmartAlbum) { - // Cannot save to smart albums other than "all photos", pick it and dismiss - [PHAssetChangeRequest creationRequestForAssetFromImage:image]; - } - else { - PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image]; - PHObjectPlaceholder *placeholder = [assetRequest placeholderForCreatedAsset]; + PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image]; + PHObjectPlaceholder *placeholder = [assetRequest placeholderForCreatedAsset]; + newAssetLocalIdentifier = placeholder.localIdentifier; + + // Cannot save to smart albums other than "all photos", pick it and dismiss + if (collection.assetCollectionType != PHAssetCollectionTypeSmartAlbum) { PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection assets:self.currentCollectionItem[@"assets"]]; [albumChangeRequest addAssets:@[placeholder]]; } @@ -429,7 +430,12 @@ - (void)imagePickerController:(UIImagePickerController *)picker didFinishPicking } if (!self.allowsMultipleSelection) { - if ([self.delegate respondsToSelector:@selector(photoPickerViewController:didFinishPickingImage:)]) { + if (NO == self.shouldReturnImageForSingleSelection) { + PHFetchResult *fetchResult = [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[newAssetLocalIdentifier] options:nil]; + PHAsset *asset = fetchResult.firstObject; + [self.selectedPhotos addObject:asset]; + [self finishPickingPhotos:nil]; + } else if ([self.delegate respondsToSelector:@selector(photoPickerViewController:didFinishPickingImage:)]) { [self.delegate photoPickerViewController:self didFinishPickingImage:image]; } else {