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

Commit

Permalink
taking photo from camera returns PHAsset if shouldReturnImageForSingl…
Browse files Browse the repository at this point in the history
…eSelection == NO
  • Loading branch information
rafaelsrocha committed Mar 28, 2018
1 parent 76072fd commit 0ea1059
Showing 1 changed file with 14 additions and 8 deletions.
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

0 comments on commit 0ea1059

Please sign in to comment.