Commit 6fe247c0 authored by Arthur.li's avatar Arthur.li

处理根据索引获取数据引起的崩溃问题

parent 739cd943
......@@ -224,10 +224,18 @@ static CGFloat TZScreenScale;
}
/// Get asset at index 获得下标为index的单个照片
/// if index beyond bounds, return nil in callback 果索引越界, 在回调中返回 nil
- (void)getAssetFromFetchResult:(id)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage completion:(void (^)(TZAssetModel *))completion {
if ([result isKindOfClass:[PHFetchResult class]]) {
PHFetchResult *fetchResult = (PHFetchResult *)result;
PHAsset *asset = fetchResult[index];
PHAsset *asset;
@try {
asset = fetchResult[index];
}
@catch (NSException* e) {
if (completion) completion(nil);
return;
}
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if (asset.mediaType == PHAssetMediaTypeVideo) type = TZAssetModelMediaTypeVideo;
......@@ -251,7 +259,12 @@ static CGFloat TZScreenScale;
[group setAssetsFilter:[ALAssetsFilter allPhotos]];
}
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
@try {
[group enumerateAssetsAtIndexes:indexSet options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
if (!result) return;
TZAssetModel *model;
TZAssetModelMediaType type = TZAssetModelMediaTypePhoto;
if (!allowPickingVideo){
......@@ -271,6 +284,11 @@ static CGFloat TZScreenScale;
}
if (completion) completion(model);
}];
}
@catch (NSException* e) {
if (completion) completion(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