Commit 6e4f4844 authored by 谭真's avatar 谭真 Committed by GitHub

Merge pull request #568 from balkarov/master

isCameraRollAlbum for all languages
parents 9050e37e b6964b93
...@@ -43,4 +43,7 @@ typedef enum : NSUInteger { ...@@ -43,4 +43,7 @@ typedef enum : NSUInteger {
@property (nonatomic, strong) NSArray *models; @property (nonatomic, strong) NSArray *models;
@property (nonatomic, strong) NSArray *selectedModels; @property (nonatomic, strong) NSArray *selectedModels;
@property (nonatomic, assign) NSUInteger selectedCount; @property (nonatomic, assign) NSUInteger selectedCount;
@property (nonatomic, assign) BOOL isCameraRoll;
@end @end
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
- (BOOL)isAssetsArray:(NSArray *)assets containAsset:(id)asset; - (BOOL)isAssetsArray:(NSArray *)assets containAsset:(id)asset;
- (NSString *)getAssetIdentifier:(id)asset; - (NSString *)getAssetIdentifier:(id)asset;
- (BOOL)isCameraRollAlbum:(NSString *)albumName; - (BOOL)isCameraRollAlbum:(id)metadata;
/// 检查照片大小是否满足最小要求 /// 检查照片大小是否满足最小要求
- (BOOL)isPhotoSelectableWithAsset:(id)asset; - (BOOL)isPhotoSelectableWithAsset:(id)asset;
......
...@@ -136,9 +136,9 @@ static dispatch_once_t onceToken; ...@@ -136,9 +136,9 @@ static dispatch_once_t onceToken;
for (PHAssetCollection *collection in smartAlbums) { for (PHAssetCollection *collection in smartAlbums) {
// 有可能是PHCollectionList类的的对象,过滤掉 // 有可能是PHCollectionList类的的对象,过滤掉
if (![collection isKindOfClass:[PHAssetCollection class]]) continue; if (![collection isKindOfClass:[PHAssetCollection class]]) continue;
if ([self isCameraRollAlbum:collection.localizedTitle]) { if ([self isCameraRollAlbum:collection]) {
PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option]; PHFetchResult *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:option];
model = [self modelWithResult:fetchResult name:collection.localizedTitle]; model = [self modelWithResult:fetchResult name:collection.localizedTitle isCameraRoll:YES];
if (completion) completion(model); if (completion) completion(model);
break; break;
} }
...@@ -146,9 +146,9 @@ static dispatch_once_t onceToken; ...@@ -146,9 +146,9 @@ static dispatch_once_t onceToken;
} else { } else {
[self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { [self.assetLibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
if ([group numberOfAssets] < 1) return; if ([group numberOfAssets] < 1) return;
if ([self isCameraRollAlbum:group]) {
NSString *name = [group valueForProperty:ALAssetsGroupPropertyName]; NSString *name = [group valueForProperty:ALAssetsGroupPropertyName];
if ([self isCameraRollAlbum:name]) { model = [self modelWithResult:group name:name isCameraRoll:YES];
model = [self modelWithResult:group name:name];
if (completion) completion(model); if (completion) completion(model);
*stop = YES; *stop = YES;
} }
...@@ -189,10 +189,10 @@ static dispatch_once_t onceToken; ...@@ -189,10 +189,10 @@ static dispatch_once_t onceToken;
if ([collection.localizedTitle tz_containsString:@"Hidden"] || [collection.localizedTitle isEqualToString:@"已隐藏"]) continue; if ([collection.localizedTitle tz_containsString:@"Hidden"] || [collection.localizedTitle isEqualToString:@"已隐藏"]) continue;
if ([collection.localizedTitle tz_containsString:@"Deleted"] || [collection.localizedTitle isEqualToString:@"最近删除"]) continue; if ([collection.localizedTitle tz_containsString:@"Deleted"] || [collection.localizedTitle isEqualToString:@"最近删除"]) continue;
if ([self isCameraRollAlbum:collection.localizedTitle]) { if ([self isCameraRollAlbum:collection]) {
[albumArr insertObject:[self modelWithResult:fetchResult name:collection.localizedTitle] atIndex:0]; [albumArr insertObject:[self modelWithResult:fetchResult name:collection.localizedTitle isCameraRoll:YES] atIndex:0];
} else { } else {
[albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle]]; [albumArr addObject:[self modelWithResult:fetchResult name:collection.localizedTitle isCameraRoll:NO]];
} }
} }
} }
...@@ -211,16 +211,16 @@ static dispatch_once_t onceToken; ...@@ -211,16 +211,16 @@ static dispatch_once_t onceToken;
} }
} }
if ([self isCameraRollAlbum:name]) { if ([self isCameraRollAlbum:group]) {
[albumArr insertObject:[self modelWithResult:group name:name] atIndex:0]; [albumArr insertObject:[self modelWithResult:group name:name isCameraRoll:YES] atIndex:0];
} else if ([name isEqualToString:@"My Photo Stream"] || [name isEqualToString:@"我的照片流"]) { } else if ([name isEqualToString:@"My Photo Stream"] || [name isEqualToString:@"我的照片流"]) {
if (albumArr.count) { if (albumArr.count) {
[albumArr insertObject:[self modelWithResult:group name:name] atIndex:1]; [albumArr insertObject:[self modelWithResult:group name:name isCameraRoll:NO] atIndex:1];
} else { } else {
[albumArr addObject:[self modelWithResult:group name:name]]; [albumArr addObject:[self modelWithResult:group name:name isCameraRoll:NO]];
} }
} else { } else {
[albumArr addObject:[self modelWithResult:group name:name]]; [albumArr addObject:[self modelWithResult:group name:name isCameraRoll:NO]];
} }
} failureBlock:nil]; } failureBlock:nil];
} }
...@@ -799,20 +799,16 @@ static dispatch_once_t onceToken; ...@@ -799,20 +799,16 @@ static dispatch_once_t onceToken;
} }
} }
- (BOOL)isCameraRollAlbum:(NSString *)albumName { - (BOOL)isCameraRollAlbum:(id)metadata {
NSString *versionStr = [[UIDevice currentDevice].systemVersion stringByReplacingOccurrencesOfString:@"." withString:@""]; if ([metadata isKindOfClass:[PHAssetCollection class]]) {
if (versionStr.length <= 1) { return ((PHAssetCollection *)metadata).assetCollectionSubtype == PHAssetCollectionSubtypeSmartAlbumUserLibrary;
versionStr = [versionStr stringByAppendingString:@"00"]; }
} else if (versionStr.length <= 2) { if ([metadata isKindOfClass:[ALAssetsGroup class]]) {
versionStr = [versionStr stringByAppendingString:@"0"]; ALAssetsGroup *group = metadata;
} return ([[group valueForProperty:ALAssetsGroupPropertyType] intValue] == ALAssetsGroupSavedPhotos);
CGFloat version = versionStr.floatValue;
// 目前已知8.0.0 - 8.0.2系统,拍照后的图片会保存在最近添加中
if (version >= 800 && version <= 802) {
return [albumName isEqualToString:@"最近添加"] || [albumName isEqualToString:@"Recently Added"];
} else {
return [albumName isEqualToString:@"Camera Roll"] || [albumName isEqualToString:@"相机胶卷"] || [albumName isEqualToString:@"所有照片"] || [albumName isEqualToString:@"All Photos"];
} }
return NO;
} }
- (NSString *)getAssetIdentifier:(id)asset { - (NSString *)getAssetIdentifier:(id)asset {
...@@ -847,10 +843,11 @@ static dispatch_once_t onceToken; ...@@ -847,10 +843,11 @@ static dispatch_once_t onceToken;
#pragma mark - Private Method #pragma mark - Private Method
- (TZAlbumModel *)modelWithResult:(id)result name:(NSString *)name{ - (TZAlbumModel *)modelWithResult:(id)result name:(NSString *)name isCameraRoll:(BOOL)isCameraRoll {
TZAlbumModel *model = [[TZAlbumModel alloc] init]; TZAlbumModel *model = [[TZAlbumModel alloc] init];
model.result = result; model.result = result;
model.name = name; model.name = name;
model.isCameraRoll = isCameraRoll;
if ([result isKindOfClass:[PHFetchResult class]]) { if ([result isKindOfClass:[PHFetchResult class]]) {
PHFetchResult *fetchResult = (PHFetchResult *)result; PHFetchResult *fetchResult = (PHFetchResult *)result;
model.count = fetchResult.count; model.count = fetchResult.count;
......
...@@ -84,7 +84,7 @@ static CGFloat itemMargin = 5; ...@@ -84,7 +84,7 @@ static CGFloat itemMargin = 5;
tzImagePickerVc.navLeftBarButtonSettingBlock(leftButton); tzImagePickerVc.navLeftBarButtonSettingBlock(leftButton);
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
} }
_showTakePhotoBtn = (([[TZImageManager manager] isCameraRollAlbum:_model.name]) && tzImagePickerVc.allowTakePicture); _showTakePhotoBtn = (_model.isCameraRoll && tzImagePickerVc.allowTakePicture);
// [self resetCachedAssets]; // [self resetCachedAssets];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChangeStatusBarOrientationNotification:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment