---
title: Configure SDK Settings
---


Configure the Sahha SDK for correct use, choose environment settings, and handle notifications.

---

## Configure

_The Sahha SDK must be configured immediately upon app launch._

{% tabs %}

{% tab label="iOS" %}

```swift {% highlighted-lines="2,7,10-14" %}
import SwiftUI
import Sahha

@main
struct MyApp: App {

  // Configure Sahha inside `init` of your app's `App` view.

  init() {
    let settings = SahhaSettings(
      environment: .sandbox, // Required - .sandbox for testing
    )
    Sahha.configure(settings) {
      // SDK is ready to use
      print("SDK Ready")
    }
  }

  var body: some Scene {
    WindowGroup {
      ContentView()
    }
  }

}
```

{% /tab %}

{% tab label="iOS (UIKit)" %}

```swift title=AppDelegate.swift {% highlighted-lines="2,7,10-17" %}
import UIKit
import Sahha

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

// Configure Sahha inside `application didFinishLaunchingWithOptions` of your app's `AppDelegate`.

  func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
    let settings = SahhaSettings(
      environment: .sandbox, // Required - .sandbox for testing
    )
    Sahha.configure(settings) {
      // SDK is ready to use
      print("SDK Ready")
    }
    return true
  }

}
```

{% /tab %}

{% tab label="Android" %}

{% callout title="Configuring your Android project" type="warning" %}

The `configure` method should be called from `MainActivity`.

Use `this` which refers to the activity itself.

All commonly used activities are extended from `ComponentActivity`.

{% /callout %}

```kotlin title=MainActivity.kt {% highlighted-lines="1,3,10-28" %}
import sdk.sahha.android.source.*

// Configure Sahha inside `onCreate` of your app's `MainActivity`.

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // You can specify optional custom notification settings
        val notificationSettings = SahhaNotificationConfiguration(
            icon = R.drapable.ic_test, // The icon id must match the filename you add to the project
            title = "Custom Title",
            shortDescription = "Custom description",
        )

        val settings = SahhaSettings (
            environment = SahhaEnvironment.sandbox,
            notificationSettings = notificationSettings, // Optional - defaults to null
        )

        Sahha.configure(this, settings) { error, success ->
            if (error != null) {
                println(error)
            } else {
                println(success.toString())
            }
        }
    }
}
```

{% /tab %}

{% tab label="Flutter" %}

{% callout title="Configuring your Android project" type="warning" %}

The default `FlutterActivity` is not lifecycle aware so it must be changed to `FlutterFragmentActivity`.

Go to your project’s `android` folder and find your `MainActivity`.

This can be found in `app` > `src` > `main` > `kotlin` > `example` > `project` > `name` > `MainActivity`.

Change `FlutterActivity` to `FlutterFragmentActivity`.

{% /callout %}

Change this:

```kotlin title=MainActivity {% highlighted-lines="4" %}
// Android MainActivity
import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity()
```

To this:

```kotlin title=MainActivity {% highlighted-lines="4" %}
// Android MainActivity
import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity()
```

Then use `configure` in your dart code like this:

```dart title=MyApp.dart {% highlighted-lines="2,10-28" %}
// Flutter Dart code
import 'package:sahha_flutter/sahha_flutter.dart';

class _MyAppState extends State<MyApp> {

  @override
  void initState() {
    super.initState();

    // Configure Sahha inside `initState` of your app's `AppState`.

    // Optional - Android only
    var notificationSettings = {
      'icon': 'Custom Icon',
      'title': 'Custom Title',
      'shortDescription': 'Custom Description'
    };

    // Use custom values
    SahhaFlutter.configure(
      environment: SahhaEnvironment.sandbox, // Required - .sandbox for testing
    .then((success) => {
      debugPrint(success.toString())
    })
    .catchError((error, stackTrace) => {
      debugPrint(error.toString())
    });

  }
}
```

{% /tab %}

{% tab label="React Native" %}

```typescript title=MyApp.tsx {% highlighted-lines="2,6,10-27" %}
import React, { useEffect } from 'react';
import Sahha, { SahhaEnvironment } from 'sahha-react-native';

export default function App() {
	// Configure Sahha inside the `useEffect` of your App's `export function`.

	useEffect(() => {
		// Use custom values
		const settings = {
			environment: SahhaEnvironment.sandbox, // Required -  .sandbox for testing
			// Optional - Android only
			notificationSettings: {
				icon: 'ic_test',
				title: 'Test Title',
				shortDescription: 'Test description.'
			}
		};

		Sahha.configure(settings, (error: string, success: boolean) => {
			console.log(`Success: ${success}`);
			if (error) {
				console.error(`Error: ${error}`);
			}
		});
	}, []);
}
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript title=MyApp.js
import { Sahha, SahhaEnvironment } from 'sahha-capacitor';

Sahha.configure({
  settings: {
    environment: SahhaEnvironment.sandbox // Required -  .sandbox for testing
    // Optional - Android only
		notificationSettings: {
			icon: 'ic_test',
			title: 'Test Title',
			shortDescription: 'Test description.'
		}
  }
}).then(
  function(response) {
    console.log(response.success);
  },
  function(error) {
    console.log(error);
  }
)
```

{% /tab %}

{% /tabs %}

---

## Environment Settings

Sahha has two servers, one for development and one for production. We recommend using the development environment until you're ready to go live. The `SahhaEnvironment` determines if the SDK connects to the `sandbox` or `production` server of the API.

| SahhaEnvironment | Description                                       |
| ---------------- | ------------------------------------------------- |
| sandbox          | For testing and debugging                         |
| production       | For public release on the App Store / Google Play |

{% callout title="Setting the incorrect environment will send data to the wrong server!" %}

- **Always** use `sandbox` during development of your app.
- **Only** use `production` when releasing your app to public users _(not for internal testing)_.

{% /callout %}


{% tabs %}

{% tab label="iOS" %}

```swift
public enum SahhaEnvironment: String {
    case sandbox
    case production
}
```

{% /tab %}

{% tab label="Android" %}

```kotlin
enum class SahhaEnvironment {
    sandbox,
    production
}
```

{% /tab %}

{% tab label="Flutter" %}

```dart
enum SahhaEnvironment {
  sandbox,
  production
}
```

{% /tab %}

{% tab label="React Native" %}

```typescript
enum SahhaEnvironment {
	sandbox,
	production
}
```

{% /tab %}

{% tab label="Ionic Capacitor" %}

```javascript
export enum SahhaEnvironment {
  sandbox = 'sandbox',
  production = 'production',
}
```

{% /tab %}

{% /tabs %}

---

## Notification Settings

Calling the Configure() function will request notification permissions if they are not already enabled. If you are not already handling notifications elsewhere in onboarding, plan when you call `configure()`. Depending on your integration flow, `configure()` may be the first SDK-related permission step the user sees.

You can customize notifications for any platform that includes an Android app.

{% callout title="You can customize notifications for the following platforms:" %}

- Android
- Flutter (Android only)
- React Native (Android only)

_**iOS apps not supported**_

{% /callout %}

---

### Custom Notification Icon

You can add an optional custom notification icon to your Android app.

{% callout title="How to create app icons with Image Asset Studio" %}

How to create app icons with Image Asset Studio

[Click here for more info](https://developer.android.com/studio/write/image-asset-studio#image)

{% /callout %}

#### Step 1) Open your project in Android Studio.

![Custom Notifications](/images/connect/sdk/android/custom_notifications_1.png)

#### Step 2) With the app folder highlighted, select`File` → `New` → `Image Asset`.

![Custom Notifications](/images/connect/sdk/android/custom_notifications_2.png)

#### Step 3) Select `Notification Icons` for `Icon Type`, enter a `Name`, select `Image` as `Asset Type` and alter the `Padding` as desired.

![Custom Notifications](/images/connect/sdk/android/custom_notifications_3.png)

#### Step 4) This page can typically be left as it is. Select `Finish`.

![Custom Notifications](/images/connect/sdk/android/custom_notifications_4.png)

---

### Custom Notification Settings

You can specify optional custom `notificationSettings`. If `notificationSettings` are not specified, then the app will use the default notification settings.

```kotlin title=Android
val notificationSettings = SahhaNotificationConfiguration(
    icon = R.drawable.ic_test, // The icon id must match the filename you add to the project
    title = "Custom Title",
    shortDescription = "Custom description",
)
```

---

### Default Notification Settings

If custom `notificationSettings` are not specified, then the app will use the default notification settings. If custom `notificationSettings` are only partially specified, then the app will use the default notification settings. The app will fill in the missing notification parameters with default values. E.g. if an `icon` and `title` are provided but a `shortDescription` is not, then the `shortDescription` will use the default value.

```kotlin title=Android
val icon = R.drawable.ic_sahha_no_bg // The Sahha logo
val title = "Gathering health insights"
val shortDescription = "Swipe for options to hide this notification."
```
