|
17 | 17 | #import <TargetConditionals.h>
|
18 | 18 | #if TARGET_OS_IOS
|
19 | 19 |
|
| 20 | +#import <sys/sysctl.h> |
| 21 | + |
20 | 22 | #import <WebKit/WebKit.h>
|
21 | 23 |
|
22 | 24 | #import "FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.h"
|
@@ -73,6 +75,19 @@ - (instancetype)initWithDelegate:(id<FIRDLJavaScriptExecutorDelegate>)delegate
|
73 | 75 |
|
74 | 76 | #pragma mark - Internal methods
|
75 | 77 | - (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 |
76 | 91 | NSString *htmlContent =
|
77 | 92 | [NSString stringWithFormat:@"<html><head><script>%@</script></head></html>", _script];
|
78 | 93 |
|
@@ -135,6 +150,21 @@ - (void)webView:(WKWebView *)webView
|
135 | 150 | [self handleExecutionError:error];
|
136 | 151 | }
|
137 | 152 |
|
| 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 | + |
138 | 168 | @end
|
139 | 169 |
|
140 | 170 | NS_ASSUME_NONNULL_END
|
|
0 commit comments