Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FirebaseDynamicLinks/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v8.0.0
- [fixed] Fixed crashes on simulators targeting below iOS14 on Apple Silicon. (#7989)

# v7.7.0
- [added] Added `utmParametersDictionary` property to `DynamicLink`. (#6730)

Expand Down
30 changes: 30 additions & 0 deletions FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import <TargetConditionals.h>
#if TARGET_OS_IOS

#import <sys/sysctl.h>

#import <WebKit/WebKit.h>

#import "FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.h"
Expand Down Expand Up @@ -73,6 +75,19 @@ - (instancetype)initWithDelegate:(id<FIRDLJavaScriptExecutorDelegate>)delegate

#pragma mark - Internal methods
- (void)start {
// Initializing a `WKWebView` causes a memory allocation error when the process
// is running under Rosetta translation on Apple Silicon.
// The issue only occurs on the simulator in apps targeting below iOS 14. (Issue #7618)
#if TARGET_OS_SIMULATOR
BOOL systemVersionAtLeastiOS14 = [NSProcessInfo.processInfo
isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){14, 0, 0}];
// Perform an early exit if the process is running under Rosetta translation and targeting
// under iOS 14.
if (processIsTranslated() && !systemVersionAtLeastiOS14) {
[self handleExecutionError:nil];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling the delegate method in the early exit case avoids interrupting the dynamic links flow and the locale property in the delegate will be set to empty string. See here

return;
}
#endif
NSString *htmlContent =
[NSString stringWithFormat:@"<html><head><script>%@</script></head></html>", _script];

Expand Down Expand Up @@ -135,6 +150,21 @@ - (void)webView:(WKWebView *)webView
[self handleExecutionError:error];
}

// Determine whether a process is running under Rosetta translation.
// Returns 0 for a native process, 1 for a translated process,
// and -1 when an error occurs.
// From:
// https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment
static int processIsTranslated() {
int ret = 0;
size_t size = sizeof(ret);
if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) {
if (errno == ENOENT) return 0;
return -1;
}
return ret;
}

@end

NS_ASSUME_NONNULL_END
Expand Down