-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DynamicLinks: Skip retrieving web locale when running targeting below iOS14 (only on simulator & Apple Silicon) #7989
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14018e4
Conditionally make WebKit allocations
ncooke3 ae8dbac
Clean up approach
ncooke3 9f3322f
Style
ncooke3 fa0bb8a
Still call delegate method
ncooke3 5e69c0b
Make C function static
ncooke3 2269c59
Updated CHANGELOG
ncooke3 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ - (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]; | ||
return; | ||
} | ||
#endif | ||
NSString *htmlContent = | ||
[NSString stringWithFormat:@"<html><head><script>%@</script></head></html>", _script]; | ||
|
||
|
@@ -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 | ||
int processIsTranslated() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make this C function static so that it does not pollute the global symbol namespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL... thanks! |
||
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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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