Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

taking photo from camera returns PHAsset if shouldReturnImageForSingleSelection == NO #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
}
Expand All @@ -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 {
Expand Down