Skip to content

added "bypassPhotoRoll" option … #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ typedef enum : NSUInteger {
@class PHAsset;
@interface TZAssetModel : NSObject

@property (nonatomic, strong) id asset; ///< PHAsset or ALAsset
@property (nonatomic, strong) id asset; ///< PHAsset, ALAsset, or UIImage (if bypassPhotoRoll is YES)
@property (nonatomic, assign) BOOL isSelected; ///< The select status of a photo, default is No
@property (nonatomic, assign) TZAssetModelMediaType type;
@property (nonatomic, copy) NSString *timeLength;
Expand Down
25 changes: 22 additions & 3 deletions TZImagePickerController/TZImagePickerController/TZImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ - (int32_t)getPhotoWithAsset:(id)asset photoWidth:(CGFloat)photoWidth completion
}
});
});
}
} else if ([asset isKindOfClass:[UIImage class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(asset,nil,NO);
});
}
return 0;
}

Expand Down Expand Up @@ -608,7 +612,11 @@ - (void)getOriginalPhotoWithAsset:(id)asset newCompletion:(void (^)(UIImage *pho
if (completion) completion(originalImage,nil,NO);
});
});
}
} else if ([asset isKindOfClass:[UIImage class]]) {
dispatch_async(dispatch_get_main_queue(), ^{
if (completion) completion(asset,nil,NO);
});
}
}

- (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *data,NSDictionary *info,BOOL isDegraded))completion {
Expand All @@ -629,7 +637,12 @@ - (void)getOriginalPhotoDataWithAsset:(id)asset completion:(void (^)(NSData *dat
NSUInteger bufferSize = [assetRep getBytes:imageBuffer fromOffset:0.0 length:assetRep.size error:nil];
NSData *imageData = [NSData dataWithBytesNoCopy:imageBuffer length:bufferSize freeWhenDone:YES];
if (completion) completion(imageData,nil,NO);
}
} else if ([asset isKindOfClass:[UIImage class]]) {
UIImage *image = asset;
NSData *imageData = CFBridgingRelease(CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage)));
if (completion) completion(imageData,nil,NO);
}

}

#pragma mark - Save photo
Expand Down Expand Up @@ -875,6 +888,9 @@ - (BOOL)isCameraRollAlbum:(id)metadata {
}

- (NSString *)getAssetIdentifier:(id)asset {
if ([asset isKindOfClass:[UIImage class]]) {
return [NSString stringWithFormat: @"%ld", (long) asset];
}
if (iOS8Later) {
PHAsset *phAsset = (PHAsset *)asset;
return phAsset.localIdentifier;
Expand All @@ -895,6 +911,9 @@ - (BOOL)isPhotoSelectableWithAsset:(id)asset {
}

- (CGSize)photoSizeWithAsset:(id)asset {
if ([asset isKindOfClass:[UIImage class]]) {
return [(UIImage*) asset size];
}
if (iOS8Later) {
PHAsset *phAsset = (PHAsset *)asset;
return CGSizeMake(phAsset.pixelWidth, phAsset.pixelHeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@
/// 默认为YES,如果设置为NO, 选择器将不会自己dismiss
@property(nonatomic, assign) BOOL autoDismiss;

/// Default is NO, if set YES, photos taken by the user are not added to the photo roll
@property(nonatomic, assign) BOOL bypassPhotoRoll;

/// The photos user have selected
/// 用户选中过的图片数组
@property (nonatomic, strong) NSMutableArray *selectedAssets;
@property (nonatomic, strong) NSMutableArray<TZAssetModel *> *selectedModels;

// Photos taken by the user, if bypassPhotoRoll is YES
@property (nonatomic, strong) NSMutableArray<TZAssetModel *> *privateModels;

/// Minimum selectable photo width, Default is 0
/// 最小可选中的图片宽度,默认是0,小于这个宽度的图片不可选中
@property (nonatomic, assign) NSInteger minPhotoWidthSelectable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@interface TZPhotoPickerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIAlertViewDelegate> {
NSMutableArray *_models;
NSMutableArray *_privateModels; // used if configured to bypass photo roll


UIView *_bottomToolBar;
UIButton *_previewButton;
Expand Down Expand Up @@ -722,31 +724,42 @@ - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingM
[imagePickerVc showProgressHUD];
UIImage *photo = [info objectForKey:UIImagePickerControllerOriginalImage];
if (photo) {
[[TZImageManager manager] savePhotoWithImage:photo location:self.location completion:^(NSError *error){
if (!error) {
[self reloadPhotoArray];
}
}];
if (imagePickerVc.bypassPhotoRoll) {
[self reloadPhotoArrayAfterTakingImage:photo];
} else {
[[TZImageManager manager] savePhotoWithImage:photo location:self.location completion:^(NSError *error){
if (!error) {
[self reloadPhotoArrayAfterTakingImage:nil];
}
}];
}
self.location = nil;
}
}
}

- (void)reloadPhotoArray {
- (void)reloadPhotoArrayAfterTakingImage:(UIImage*) inImage {
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
[[TZImageManager manager] getCameraRollAlbum:tzImagePickerVc.allowPickingVideo allowPickingImage:tzImagePickerVc.allowPickingImage needFetchAssets:NO completion:^(TZAlbumModel *model) {
_model = model;
[[TZImageManager manager] getAssetsFromFetchResult:_model.result completion:^(NSArray<TZAssetModel *> *models) {
[tzImagePickerVc hideProgressHUD];

TZAssetModel *assetModel;
if (tzImagePickerVc.sortAscendingByModificationDate) {
assetModel = [models lastObject];
[_models addObject:assetModel];
} else {
assetModel = [models firstObject];
[_models insertObject:assetModel atIndex:0];
}

if (inImage) {
assetModel = [TZAssetModel modelWithAsset:inImage type:TZAssetModelMediaTypePhoto];
[_models addObject:assetModel];
}
else {
if (tzImagePickerVc.sortAscendingByModificationDate) {
assetModel = [models lastObject];
[_models addObject:assetModel];
} else {
assetModel = [models firstObject];
[_models insertObject:assetModel atIndex:0];
}
}

if (tzImagePickerVc.maxImagesCount <= 1) {
if (tzImagePickerVc.allowCrop) {
Expand Down
8 changes: 5 additions & 3 deletions TZImagePickerController/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPa
ALAsset *alAsset = asset;
isVideo = [[alAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo];
}
if ([[asset valueForKey:@"filename"] tz_containsString:@"GIF"] && self.allowPickingGifSwitch.isOn && !self.allowPickingMuitlpleVideoSwitch.isOn) {
if (![asset isKindOfClass:[UIImage class]] && [[asset valueForKey:@"filename"] tz_containsString:@"GIF"] && self.allowPickingGifSwitch.isOn && !self.allowPickingMuitlpleVideoSwitch.isOn) {
TZGifPhotoPreviewController *vc = [[TZGifPhotoPreviewController alloc] init];
TZAssetModel *model = [TZAssetModel modelWithAsset:asset type:TZAssetModelMediaTypePhotoGif timeLength:@""];
vc.model = model;
Expand Down Expand Up @@ -493,8 +493,10 @@ - (void)imagePickerController:(TZImagePickerController *)picker didFinishPicking
[self printAssetsName:assets];
// 2.图片位置信息
if (iOS8Later) {
for (PHAsset *phAsset in assets) {
NSLog(@"location:%@",phAsset.location);
for (id phAsset in assets) {
if ([phAsset isKindOfClass:[PHAsset class]]) {
NSLog(@"location:%@",[(PHAsset*)phAsset location]);
}
}
}
}
Expand Down