Skip to content

Commit

Permalink
Conditionally make WebKit allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 committed Apr 20, 2021
1 parent b780014 commit 14018e4
Showing 1 changed file with 30 additions and 0 deletions.
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 @@ -66,7 +68,20 @@ - (instancetype)initWithDelegate:(id<FIRDLJavaScriptExecutorDelegate>)delegate
if (self = [super init]) {
_delegate = delegate;
_script = [script copy];

// A WebKit memory allocation error occurs on Apple Silicon when the
// target is below iOS 14. The issue only occurs on the simulator.
#if TARGET_OS_SIMULATOR
// Only make WebKit related memory allocations if the process
// is not running under Rosetta translation.
if (!processIsTranslated()) {

This comment has been minimized.

Copy link
@paulb777

paulb777 Apr 20, 2021

Member

should there also be a check for iOS 13 and below?

// The `start:` method allocates a WebKit object.
[self start];
}
#else
[self start];
#endif

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

// Determine whether a process is running on a Rosetta translation.
// Return 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() {
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

0 comments on commit 14018e4

Please sign in to comment.