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
This commit is contained in:
Nick Cooke authored and GitHub committed 2021-04-27 20:55:37 -04:00
1 parent d695438f59
commit 8be7fa5996
2 files changed
+33

No files matched your search

@@ -17,6 +17,8 @@
#import <TargetConditionals.h>
#if TARGET_OS_IOS
#import <sys/sysctl.h>
#import <WebKit/WebKit.h>
#import "FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.h"
@@ -73,6 +75,19 @@ NSString *GINFingerprintJSMethodString(void) {
#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];
return;
}
#endif
NSString *htmlContent =
[NSString stringWithFormat:@"<html><head><script>%@</script></head></html>", _script];
@@ -135,6 +150,21 @@ NSString *GINFingerprintJSMethodString(void) {
[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