Skip to content

Commit 8be7fa5

Browse files
authored
DynamicLinks: Skip retrieving web locale when running targeting below iOS14 (only on simulator & Apple Silicon) (#7989)
* Conditionally make WebKit allocations * Clean up approach * Style * Still call delegate method * Make C function static * Updated CHANGELOG
1 parent d695438 commit 8be7fa5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

FirebaseDynamicLinks/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v8.0.0
2+
- [fixed] Fixed crashes on simulators targeting below iOS14 on Apple Silicon. (#7989)
3+
14
# v7.7.0
25
- [added] Added `utmParametersDictionary` property to `DynamicLink`. (#6730)
36

FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#import <TargetConditionals.h>
1818
#if TARGET_OS_IOS
1919

20+
#import <sys/sysctl.h>
21+
2022
#import <WebKit/WebKit.h>
2123

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

7476
#pragma mark - Internal methods
7577
- (void)start {
78+
// Initializing a `WKWebView` causes a memory allocation error when the process
79+
// is running under Rosetta translation on Apple Silicon.
80+
// The issue only occurs on the simulator in apps targeting below iOS 14. (Issue #7618)
81+
#if TARGET_OS_SIMULATOR
82+
BOOL systemVersionAtLeastiOS14 = [NSProcessInfo.processInfo
83+
isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){14, 0, 0}];
84+
// Perform an early exit if the process is running under Rosetta translation and targeting
85+
// under iOS 14.
86+
if (processIsTranslated() && !systemVersionAtLeastiOS14) {
87+
[self handleExecutionError:nil];
88+
return;
89+
}
90+
#endif
7691
NSString *htmlContent =
7792
[NSString stringWithFormat:@"<html><head><script>%@</script></head></html>", _script];
7893

@@ -135,6 +150,21 @@ - (void)webView:(WKWebView *)webView
135150
[self handleExecutionError:error];
136151
}
137152

153+
// Determine whether a process is running under Rosetta translation.
154+
// Returns 0 for a native process, 1 for a translated process,
155+
// and -1 when an error occurs.
156+
// From:
157+
// https://developer.apple.com/documentation/apple-silicon/about-the-rosetta-translation-environment
158+
static int processIsTranslated() {
159+
int ret = 0;
160+
size_t size = sizeof(ret);
161+
if (sysctlbyname("sysctl.proc_translated", &ret, &size, NULL, 0) == -1) {
162+
if (errno == ENOENT) return 0;
163+
return -1;
164+
}
165+
return ret;
166+
}
167+
138168
@end
139169

140170
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)