@@ -162,7 +162,8 @@ - (void) photos:(CDVInvokedUrlCommand*)command {
162
162
}
163
163
164
164
int __block fetched = 0 ;
165
- NSMutableArray <NSDictionary *>* result = [NSMutableArray array ];
165
+ NSMutableArray <PHAsset*>* __block skippedAssets = [NSMutableArray array ];
166
+ NSMutableArray <NSDictionary *>* __block result = [NSMutableArray array ];
166
167
[fetchResultAssetCollections enumerateObjectsUsingBlock:
167
168
^(PHAssetCollection* _Nonnull assetCollection, NSUInteger idx, BOOL * _Nonnull stop) {
168
169
if ([weakSelf isNull: weakSelf.photosCommand]) {
@@ -185,19 +186,16 @@ - (void) photos:(CDVInvokedUrlCommand*)command {
185
186
*stop = YES ;
186
187
return ;
187
188
}
188
- PHAssetResource* resource = [weakSelf resourceForAsset : asset];
189
- if (resource != nil ) {
189
+ NSString * filename = [weakSelf getFilenameForAsset : asset];
190
+ if (![weakSelf isNull: filename] ) {
190
191
NSTextCheckingResult * match
191
192
= [weakSelf.extRegex
192
- firstMatchInString: resource.originalFilename
193
+ firstMatchInString: filename
193
194
options: 0
194
- range: NSMakeRange (0 , resource.originalFilename .length)];
195
+ range: NSMakeRange (0 , filename .length)];
195
196
if (match != nil ) {
196
- NSString * name = [resource.originalFilename
197
- substringWithRange: [match rangeAtIndex: 1 ]];
198
- NSString * ext = [[resource.originalFilename
199
- substringWithRange: [match rangeAtIndex: 2 ]]
200
- uppercaseString ];
197
+ NSString * name = [filename substringWithRange: [match rangeAtIndex: 1 ]];
198
+ NSString * ext = [[filename substringWithRange: [match rangeAtIndex: 2 ]] uppercaseString ];
201
199
NSString * type = weakSelf.extType [ext];
202
200
if (![weakSelf isNull: type]) {
203
201
if (offset <= fetched) {
@@ -224,11 +222,17 @@ - (void) photos:(CDVInvokedUrlCommand*)command {
224
222
}
225
223
}
226
224
++fetched;
227
- }
228
- }
229
- }
225
+ } else [skippedAssets addObject: asset];
226
+ } else [skippedAssets addObject: asset];
227
+ } else [skippedAssets addObject: asset];
230
228
}];
231
229
}];
230
+ [skippedAssets enumerateObjectsUsingBlock: ^(PHAsset* _Nonnull asset, NSUInteger idx, BOOL * _Nonnull stop) {
231
+ NSLog (@" skipped asset %lu : id=%@ ; name=%@ , type=%ld -%ld ; size=%lu x%lu ;" ,
232
+ idx, asset.localIdentifier , [weakSelf getFilenameForAsset: asset],
233
+ (long )asset.mediaType , (long )asset.mediaSubtypes ,
234
+ (unsigned long )asset.pixelWidth , asset.pixelHeight );
235
+ }];
232
236
weakSelf.photosCommand = nil ;
233
237
[weakSelf success: command withArray: result];
234
238
}];
@@ -386,16 +390,22 @@ - (PHAsset*) assetByCommand:(CDVInvokedUrlCommand*)command {
386
390
return asset;
387
391
}
388
392
389
- - (PHAssetResource*) resourceForAsset : (PHAsset*)asset {
390
- PHAssetResource* __block result = nil ;
391
- [[PHAssetResource assetResourcesForAsset: asset] enumerateObjectsUsingBlock:
392
- ^(PHAssetResource* _Nonnull resource, NSUInteger idx, BOOL * _Nonnull stop) {
393
- if (resource.type == PHAssetResourceTypePhoto) {
394
- result = resource;
395
- *stop = YES ;
396
- }
397
- }];
398
- return result;
393
+ - (NSString *) getFilenameForAsset : (PHAsset*)asset {
394
+ // Works fine, but asynchronous ((.
395
+ // [asset
396
+ // requestContentEditingInputWithOptions:nil
397
+ // completionHandler:^(PHContentEditingInput* _Nullable contentEditingInput, NSDictionary* _Nonnull info) {
398
+ // NSString* filename = [[contentEditingInput.fullSizeImageURL.absoluteString componentsSeparatedByString:@"/"] lastObject];
399
+ // }];
400
+
401
+ // Most optimal and fast, but it's dirty hack
402
+ return [asset valueForKey: @" filename" ];
403
+
404
+ // assetResourcesForAsset doesn't work properly for all images.
405
+ // Moreover, it obtains resource for very long time - too long for just a file name.
406
+ // NSArray<PHAssetResource*>* resources = [PHAssetResource assetResourcesForAsset:asset];
407
+ // if ([self isNull:resources] || resources.count == 0) return nil;
408
+ // return resources[0].originalFilename;
399
409
}
400
410
401
411
- (PHFetchResult<PHAssetCollection*>*) fetchCollections : (NSDictionary *)options {
0 commit comments