# launchApp

Use this command to start a mobile app.

## Examples

### Launch the uploaded app

To launch the app you uploaded to Moropo, simply call without options:

```yaml
- launchApp
```

### Launch a different app

To launch a specific app (no one you've uploaded to Moropo), use the `appId` option to supply an iOS Bundle ID or Android Package Name:

```yaml
- launchApp:
    appId: com.facebook.app
```

### Stop the app before launching

The `stopApp` option is `true` by default. If you set it to `false` the test runner won't attempt to close the running app before launch.

```yaml
- launchApp:
    stopApp: false
```

### Clearing application state during launch

Similar to the standalone [clearState command](https://docs.moropo.com/creating-tests/commands/clearstate), this option will erase the application data part of the launch process. Defaults to `false`.

```yaml
- launchApp:
    clearState: true
```

Note: clearState does not affect [permissions](#permissions) configured.

### Clearing the keychain during launch (iOS only)

Similar to the standalone [clearKeychain command](https://docs.moropo.com/creating-tests/commands/clearkeychain), this option will erase the entire iOS keychain as part of the launch process. Defaults to `false`.

```yaml
- launchApp:
    clearKeychain: true
```

## Permissions

Use the permissions option to customise which permissions are accepted, denied or unset by the virtual device being tested. By default, all permissions are allowed.

For example, to disallow every permission:

```yaml
- launchApp:
    permissions: { all: deny }
```

To unset `notifications` and deny `camera`:

```yaml
- launchApp:
    permissions:
        camera: deny
        notifications: unset
```

### List of all standard permissions

| Permission         | iOS support          | Android support      |
| ------------------ | -------------------- | -------------------- |
| bluetooth          | ❌                    | :white\_check\_mark: |
| calendar           | :white\_check\_mark: | :white\_check\_mark: |
| camera             | :white\_check\_mark: | :white\_check\_mark: |
| contacts           | :white\_check\_mark: | :white\_check\_mark: |
| health             | ❌                    | ❌                    |
| homekit            | :white\_check\_mark: | ❌                    |
| location           | :white\_check\_mark: | :white\_check\_mark: |
| medialibrary       | :white\_check\_mark: | :white\_check\_mark: |
| microphone         | :white\_check\_mark: | :white\_check\_mark: |
| motion             | :white\_check\_mark: | ❌                    |
| notifications      | :white\_check\_mark: | :white\_check\_mark: |
| phone              | ❌                    | :white\_check\_mark: |
| photos             | :white\_check\_mark: | ❌                    |
| reminders          | :white\_check\_mark: | ❌                    |
| siri               | :white\_check\_mark: | ❌                    |
| sms                | ❌                    | :white\_check\_mark: |
| speech             | :white\_check\_mark: | ❌                    |
| storage            | ❌                    | :white\_check\_mark: |
| usertracking       | :white\_check\_mark: | ❌                    |
| *something.custom* | ❌                    | :white\_check\_mark: |

##

## Launching with arguments

Launch arguments are variables that are injected into your app at start-up time. They're useful for triggering certain behaviours inside your app code. For example, telling your app to use a mock API.

### Using the arguments option

You can send the following types of data: `String`, `Integer`, `Double` or `Boolean`. Data that doesn't match one of these formats will be parsed as a string.

```yaml
- launchApp:
    arguments:
      myString: "This sentence is a string"
      myInteger: 123
      myDouble: 123.05
      myBoolean: true
```

### Accessing launch arguments on React Native

Use the [react-native-launch-arguments](https://www.npmjs.com/package/react-native-launch-arguments) package to access arguments in your React Native app.

In JavaScript

```javascript
import { LaunchArguments } from "react-native-launch-arguments";
const { myBoolean, myString } = LaunchArguments.value();
```

### Accessing launch arguments on iOS

Using Swift:

```swift
if CommandLine.arguments.contains("myBoolean") {
    // myBoolean is true
}

let userDefaults = UserDefaults.standard
let mySentence = userDefaults.string(forKey: "myString") ?? "defaultValue"
```

Using Objective C:

```objectivec
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
if ([arguments containsObject:@"myBoolean"]) {
    // myBoolean is true
}

NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *mySentence = [userDefaults stringForKey:@"myString"] ?: @"defaultValue";

```

### Accessing launch arguments on Android

Using Kotlin:

```kotlin
intent.extras?.getBoolean("myBoolean")?.let { myBoolean ->
    // Do something with myBoolean (Boolean type)
}

intent.extras?.getString("myString")?.let { myString ->
    // Do something with myString (String type)
}
```

Using Java:

```java
Bundle extras = intent.getExtras();
if (extras != null) {
    if (extras.containsKey("myBoolean")) {
        boolean myBoolean = extras.getBoolean("myBoolean");
        // Do something with myBoolean (boolean type)
    }

    if (extras.containsKey("myString")) {
        String myString = extras.getString("myString");
        // Do something with myString (String type)
    }
}

```

## Related Commands

[stopapp](https://docs.moropo.com/creating-tests/commands/stopapp "mention")
