Skip to content

Commit

Permalink
feat: allow passing cli args when running in the iOS Simulator (#5518)
Browse files Browse the repository at this point in the history
* Allow passing command line arguments when running an app in the iOS Simulator

The `IOS_SIMULATOR_RUN_ARGS` environment variable allows specific command line arguments
to be passed to the simulator when running an app.

This is _extremely_ useful when working (for example) with Firebase and having to debug
events or other internals:

https://firebase.google.com/docs/analytics/debugview

The command line arguments `-FIRDebugEnabled` and `-FIRDebugDisabled` control the behavior
of Firebase in combination with its realtime event debugging console.

With this patch, enabling debugging is as easy as calling:

```bash
IOS_SIMULATOR_RUN_ARGS=-FIRDebugEnabled ns run ios
```

* Add documentation for `IOS_SIMULATOR_RUN_ARGS` variable

* Update docs/man_pages/project/testing/run-ios.md

Co-authored-by: Igor Randjelovic <rigor789@gmail.com>
  • Loading branch information
pfumagalli and rigor789 authored Jun 1, 2021
1 parent ce0c714 commit 6b700b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/man_pages/project/testing/run-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Start an emulator with specified device identifier and sdk | `$ tns run ios [--d
* `--env.hiddenSourceMap` - creates sources maps in the root folder (useful for Crashlytics usage with bundled app in release).
* `--force` - If set, skips the application compatibility checks and forces `npm i` to ensure all dependencies are installed. Otherwise, the command will check the application compatibility with the current CLI version and could fail requiring `tns migrate`.

### Environment Variables

* `IOS_SIMULATOR_RUN_ARGS` - specifies extra command line arguments to pass to the application when running on the iOS Simulator. E.g. `$ IOS_SIMULATOR_RUN_ARGS=-FIRDebugEnabled ns device run ios`.

<% } %>
<% if(isHtml) { %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export class IOSSimulatorApplicationManager extends ApplicationManagerBase {
public async startApplication(
appData: Mobile.IStartApplicationData
): Promise<void> {
const args = process.env.IOS_SIMULATOR_RUN_ARGS || "";
const options = appData.waitForDebugger
? {
waitForDebugger: true,
args: "--nativescript-debug-brk",
args: `--nativescript-debug-brk ${args}`.trim(),
}
: args
? { args }
: {};
await this.setDeviceLogData(appData);
const launchResult = await this.iosSim.startApplication(
Expand Down

0 comments on commit 6b700b4

Please sign in to comment.