Skip to content

Commit

Permalink
[cli] Warn user when trying to an iOS app in a incompatible device (#194
Browse files Browse the repository at this point in the history
)

* [cli] Warn user when trying to an iOS app in a incompatible device

* Prevent detectIOSAppType from erroring out

* Apply suggestions from code review

Co-authored-by: Brent Vatne <brentvatne@gmail.com>

* Add changelog entry

---------

Co-authored-by: Brent Vatne <brentvatne@gmail.com>
  • Loading branch information
gabrieldonadel and brentvatne committed Mar 15, 2024
1 parent c6b6ffa commit e7ad094
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,8 @@

### 💡 Others

- Add warning when trying to an iOS app in a incompatible device. ([#194](https://github.com/expo/orbit/pull/194) by [@gabrieldonadel](https://github.com/gabrieldonadel))

## 1.1.0 — 2024-03-06

### 🎉 New features
Expand Down
21 changes: 20 additions & 1 deletion apps/cli/src/commands/InstallAndLaunchApp.ts
@@ -1,4 +1,10 @@
import { Emulator, Simulator, extractAppFromLocalArchiveAsync, AppleDevice } from 'eas-shared';
import {
Emulator,
Simulator,
extractAppFromLocalArchiveAsync,
AppleDevice,
detectIOSAppType,
} from 'eas-shared';
import { Platform } from 'common-types/build/cli-commands';

import { getPlatformFromURI } from '../utils';
Expand All @@ -21,13 +27,26 @@ export async function installAndLaunchAppAsync(options: InstallAndLaunchAppAsync
}

async function installAndLaunchIOSAppAsync(appPath: string, deviceId: string) {
const appType = await detectIOSAppType(appPath);

if (await Simulator.isSimulatorAsync(deviceId)) {
if (appType === 'device') {
throw new Error(
"iOS apps built to target physical devices can't be installed on simulators. Either use a physical device or generate a new simulator build."
);
}

const bundleIdentifier = await Simulator.getAppBundleIdentifierAsync(appPath);
await Simulator.installAppAsync(deviceId, appPath);
await Simulator.launchAppAsync(deviceId, bundleIdentifier);
return;
}

if (appType === 'simulator') {
throw new Error(
"iOS simulator builds can't be installed on physical devices. Either use a simulator or generate an internal distribution build."
);
}
const appId = await AppleDevice.getBundleIdentifierForBinaryAsync(appPath);
await AppleDevice.installOnDeviceAsync({
bundleIdentifier: appId,
Expand Down
3 changes: 2 additions & 1 deletion packages/eas-shared/src/index.ts
Expand Up @@ -3,7 +3,7 @@ import {
AppPlatform,
extractAppFromLocalArchiveAsync,
} from './download';
import { runAppOnIosSimulatorAsync, runAppOnAndroidEmulatorAsync } from './run';
import { runAppOnIosSimulatorAsync, runAppOnAndroidEmulatorAsync, detectIOSAppType } from './run';
import * as Emulator from './run/android/emulator';
import { assertExecutablesExistAsync as validateAndroidSystemRequirementsAsync } from './run/android/systemRequirements';
import AppleDevice from './run/ios/device';
Expand All @@ -21,6 +21,7 @@ export {
runAppOnAndroidEmulatorAsync,
validateAndroidSystemRequirementsAsync,
validateIOSSystemRequirementsAsync,
detectIOSAppType,
Emulator,
Simulator,
AppleDevice,
Expand Down
1 change: 1 addition & 0 deletions packages/eas-shared/src/run/index.ts
Expand Up @@ -5,6 +5,7 @@ import * as Simulator from './ios/simulator';
import { validateSystemRequirementsAsync } from './ios/systemRequirements';
import { assertExecutablesExistAsync } from './android/systemRequirements';
import { getAptParametersAsync } from './android/aapt';
export { detectIOSAppType } from './ios/inspectApp';

export async function runAppOnIosSimulatorAsync(
appPath: string,
Expand Down
16 changes: 16 additions & 0 deletions packages/eas-shared/src/run/ios/inspectApp.ts
@@ -0,0 +1,16 @@
import path from 'path';
import fs from 'fs-extra';

import { parseBinaryPlistAsync } from '../../utils/parseBinaryPlistAsync';

export async function detectIOSAppType(appPath: string): Promise<'device' | 'simulator'> {
const builtInfoPlistPath = path.join(appPath, 'Info.plist');
if (!fs.existsSync(builtInfoPlistPath)) {
return 'device';
}

const { DTPlatformName }: { DTPlatformName: string } =
await parseBinaryPlistAsync(builtInfoPlistPath);

return DTPlatformName.includes('simulator') ? 'simulator' : 'device';
}

0 comments on commit e7ad094

Please sign in to comment.