Skip to content

Commit 1282855

Browse files
fix(dynamic-links): fix crash when building dynamic link with no internet (#9942)
1 parent f47c5ec commit 1282855

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/firebase_dynamic_links/firebase_dynamic_links/ios/Classes/FLTFirebaseDynamicLinksPlugin.m

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,42 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
123123
FLTFirebaseMethodCallErrorBlock errorBlock = ^(
124124
NSString *_Nullable code, NSString *_Nullable message, NSDictionary *_Nullable details,
125125
NSError *_Nullable error) {
126+
NSMutableDictionary *temp;
126127
if (code == nil) {
127128
NSDictionary *errorDetails = getDictionaryFromNSError(error);
128129
code = errorDetails[kCode];
129130
message = errorDetails[kMessage];
130-
details = errorDetails;
131+
132+
if (errorDetails[@"additionalData"] != nil) {
133+
temp = [errorDetails[@"additionalData"] mutableCopy];
134+
} else {
135+
temp = [errorDetails mutableCopy];
136+
}
137+
138+
// "NSErrorFailingURLStringKey" key does not work for removing this object. So we use our own
139+
// String to retrieve
140+
if (temp[@"NSErrorFailingURLKey"] != nil) {
141+
[temp removeObjectForKey:@"NSErrorFailingURLKey"];
142+
}
143+
if (temp[NSUnderlyingErrorKey] != nil) {
144+
[temp removeObjectForKey:NSUnderlyingErrorKey];
145+
}
146+
147+
if ([errorDetails[kMessage] containsString:@"An unknown error has occurred"] &&
148+
[temp[NSLocalizedDescriptionKey] containsString:@"The request timed out"]) {
149+
message = temp[NSLocalizedDescriptionKey];
150+
}
131151

132152
if (errorDetails[@"additionalData"][NSLocalizedFailureReasonErrorKey] != nil) {
133153
// This stops an uncaught type cast exception in dart
134-
NSMutableDictionary *temp = [errorDetails[@"additionalData"] mutableCopy];
135154
[temp removeObjectForKey:NSLocalizedFailureReasonErrorKey];
136-
details = temp;
137155
// provides a useful message to the user. e.g. "Universal link URL could not be parsed".
138156
if ([message containsString:@"unknown error"]) {
139157
message = errorDetails[@"additionalData"][NSLocalizedFailureReasonErrorKey];
140158
}
141159
}
160+
161+
details = temp;
142162
} else {
143163
details = @{
144164
kCode : code,

0 commit comments

Comments
 (0)