Skip to content

Commit c321e9d

Browse files
author
Miguel Ruivo
authored
Merge pull request miguelpruivo#1041 from blaugold/fix/file-utils-resolve-type
Handle `UTTypeCreatePreferredIdentifierForTag` returning `NULL`
2 parents 5b9dc6e + 8a8af5b commit c321e9d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 4.6.1
2+
3+
#### iOS
4+
Handle `UTTypeCreatePreferredIdentifierForTag` returning `NULL`. This prevents a crash observed
5+
on the iOS simulator on Apple Silicon ([#1040](https://github.com/miguelpruivo/flutter_file_picker/issues/783)).
6+
17
## 4.6.0
28

39
#### iOS

ios/Classes/FileUtils.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,18 @@ + (BOOL) clearTemporaryFiles {
4747

4848
NSMutableArray<NSString*>* utis = [[NSMutableArray<NSString*> alloc] init];
4949

50-
for(int i = 0 ; i<allowedExtensions.count ; i++){
50+
for(int i = 0 ; i<allowedExtensions.count ; i++) {
5151
NSString * format = [NSString stringWithFormat:@"dummy.%@", allowedExtensions[i]];
5252
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[format pathExtension], NULL);
5353
NSString * UTIString = (__bridge NSString *)(UTI);
54-
CFRelease(UTI);
55-
if([UTIString containsString:@"dyn."]){
54+
if (UTI) CFRelease(UTI);
55+
if (!UTI) {
56+
Log(@"[Skipping type] Resolving type from extension is not supported: %@", allowedExtensions[i]);
57+
continue;
58+
} else if ([UTIString containsString:@"dyn."]) {
5659
Log(@"[Skipping type] Unsupported file type: %@", UTIString);
5760
continue;
58-
} else{
61+
} else {
5962
Log(@"Custom file type supported: %@", UTIString);
6063
[utis addObject: UTIString];
6164
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
33
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
44
repository: https://github.com/miguelpruivo/flutter_file_picker
55
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
6-
version: 4.6.0
6+
version: 4.6.1
77

88
dependencies:
99
flutter:

0 commit comments

Comments
 (0)