Skip to content

Commit

Permalink
Use defaults command to update scheme approval settings (#622)
Browse files Browse the repository at this point in the history
This PR changes the way we update scheme approval list for launching
apps via deep links.

Previously, we'd manually modify plist files under the simulator
"filesystem". This wouldn't work in some cases, as the content of the
file could be cached by some of the system services. Modifying it using
the defaults command seem to resolve the issue and always results in the
simulator reflecting the made changes.

For some reason the previous approach would work most of the time, as
we'd typically boot the device prior to launching. However, under
certain cirmustances (that are difficult to replicate), it would use a
booted version that already had the plist file loaded. As a consequence,
the app would get stuck on the "Waiting for app to load" message as the
app process would get stuck on the system dialog asking whether the link
can be opened with the installed app.

Fixes #544

### How Has This Been Tested: 
1. Create new iOS simulator - launch expo dev client app and expo go app
2. Use `defaults read com.apple.launchservices.schemeapproval` to read
the updated content.
  • Loading branch information
kmagiera authored Oct 14, 2024
1 parent cdd2c22 commit 0284dd7
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions packages/vscode-extension/src/devices/IosSimulatorDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,26 +278,25 @@ export class IosSimulatorDevice extends DeviceBase {

async launchWithExpoDeeplink(bundleID: string, expoDeeplink: string) {
// For Expo dev-client and Expo Go setup, we use deeplink to launch the app. For this approach to work we do the following:
// 1. Add the deeplink to the scheme approval list
// 1. Add the deeplink to the scheme approval list via defaults
// 2. Terminate the app if it's running
// 3. Open the deeplink
const deviceSetLocation = getOrCreateDeviceSet(this.deviceUDID);

// Add the deeplink to the scheme approval list:
const schema = new URL(expoDeeplink).protocol.slice(0, -1);
await exec("/usr/libexec/PlistBuddy", [
"-c",
"Clear dict",
"-c",
`Add :com.apple.CoreSimulator.CoreSimulatorBridge-->${schema} string ${bundleID}`,
path.join(
deviceSetLocation,
this.deviceUDID,
"data",
"Library",
"Preferences",
"com.apple.launchservices.schemeapproval.plist"
),
await exec("xcrun", [
"simctl",
"--set",
deviceSetLocation,
"spawn",
this.deviceUDID,
"defaults",
"write",
"com.apple.launchservices.schemeapproval",
`com.apple.CoreSimulator.CoreSimulatorBridge-->${schema}`,
"-string",
bundleID,
]);

// Terminate the app if it's running:
Expand Down

0 comments on commit 0284dd7

Please sign in to comment.