Skip to content

Commit e9a5155

Browse files
authored
Merge pull request itinance#1 from IntelexTechnologies/iOS_crashes
RNFSManager iOS crash in readDir
2 parents 087db72 + 24492fa commit e9a5155

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

RNFSManager.m

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,27 @@ + (BOOL)requiresMainQueueSetup
5757
NSError *error = nil;
5858

5959
NSArray *contents = [fileManager contentsOfDirectoryAtPath:dirPath error:&error];
60-
61-
contents = [contents rnfs_mapObjectsUsingBlock:^id(NSString *obj, NSUInteger idx) {
60+
NSMutableArray *tagetContents = [[NSMutableArray alloc] init];
61+
for (NSString *obj in contents) {
6262
NSString *path = [dirPath stringByAppendingPathComponent:obj];
6363
NSDictionary *attributes = [fileManager attributesOfItemAtPath:path error:nil];
64-
65-
return @{
66-
@"ctime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileCreationDate]],
67-
@"mtime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileModificationDate]],
68-
@"name": obj,
69-
@"path": path,
70-
@"size": [attributes objectForKey:NSFileSize],
71-
@"type": [attributes objectForKey:NSFileType]
72-
};
73-
}];
64+
if(attributes != nil) {
65+
[tagetContents addObject:@{
66+
@"ctime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileCreationDate]],
67+
@"mtime": [self dateToTimeIntervalNumber:(NSDate *)[attributes objectForKey:NSFileModificationDate]],
68+
@"name": obj,
69+
@"path": path,
70+
@"size": [attributes objectForKey:NSFileSize],
71+
@"type": [attributes objectForKey:NSFileType]
72+
}];
73+
}
74+
}
7475

7576
if (error) {
7677
return [self reject:reject withError:error];
7778
}
7879

79-
resolve(contents);
80+
resolve(tagetContents);
8081
}
8182

8283
RCT_EXPORT_METHOD(exists:(NSString *)filepath

0 commit comments

Comments
 (0)