fix a crash bug when image url is unavailable

This commit is contained in:
钟铿 2024-08-14 15:01:46 +08:00
parent 6d098eeb3b
commit 2a19d9c36c
1 changed files with 5 additions and 0 deletions

View File

@ -64,6 +64,11 @@ static NSString * const SDDiskCacheExtendedAttributeName = @"com.hackemist.SDDis
- (NSData *)dataForKey:(NSString *)key {
NSParameterAssert(key);
NSString *filePath = [self cachePathForKey:key];
// if filePath is nil or (null)framework will crash with this
// Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[_NSPlaceholderData initWithContentsOfFile:options:maxLength:error:]: nil file argument'
if (filePath == nil || [@"(null)" isEqualToString: filePath]) {
return nil;
}
NSData *data = [NSData dataWithContentsOfFile:filePath options:self.config.diskCacheReadingOptions error:nil];
if (data) {
return data;