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 86b7fe2
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions YangMingShan/YMSPhotoPicker/Public/YMSPhotoPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,38 @@ - (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"];
PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
if (collection.assetCollectionType == PHAssetCollectionTypeSmartAlbum) {
// Cannot save to smart albums other than "all photos", pick it and dismiss
[PHAssetChangeRequest creationRequestForAssetFromImage:image];

PHObjectPlaceholder *placeholder = [assetRequest placeholderForCreatedAsset];
newAssetLocalIdentifier = placeholder.localIdentifier;
}
else {
PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
PHObjectPlaceholder *placeholder = [assetRequest placeholderForCreatedAsset];
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection assets:self.currentCollectionItem[@"assets"]];
[albumChangeRequest addAssets:@[placeholder]];
newAssetLocalIdentifier = placeholder.localIdentifier;
}
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
self.needToSelectFirstPhoto = YES;
}

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 86b7fe2

Please sign in to comment.