Configure the Sahha SDK for correct use, choose environment settings, and handle notifications.
Configure
The Sahha SDK must be configured immediately upon app launch.
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()
}
}
} 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
}
} Configuring your Android project
The configure method should be called from MainActivity.
Use this which refers to the activity itself.
All commonly used activities are extended from ComponentActivity.
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())
}
}
}
} Configuring your Android project
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.
Change this:
// Android MainActivity
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() To this:
// Android MainActivity
import io.flutter.embedding.android.FlutterFragmentActivity
class MainActivity: FlutterFragmentActivity() Then use configure in your dart code like this:
// 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())
});
}
} 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}`);
}
});
}, []);
} 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);
}
) 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 |
Setting the incorrect environment will send data to the wrong server!
- Always use
sandboxduring development of your app. - Only use
productionwhen releasing your app to public users (not for internal testing).
public enum SahhaEnvironment: String {
case sandbox
case production
} enum class SahhaEnvironment {
sandbox,
production
} enum SahhaEnvironment {
sandbox,
production
} enum SahhaEnvironment {
sandbox,
production
} export enum SahhaEnvironment {
sandbox = 'sandbox',
production = 'production',
} 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.
You can customize notifications for the following platforms:
- Android
- Flutter (Android only)
- React Native (Android only)
iOS apps not supported
Custom Notification Icon
You can add an optional custom notification icon to your Android app.
How to create app icons with Image Asset Studio
How to create app icons with Image Asset Studio
Step 1) Open your project in Android Studio.
Step 2) With the app folder highlighted, selectFile → New → Image Asset.
Step 3) Select Notification Icons for Icon Type, enter a Name, select Image as Asset Type and alter the Padding as desired.
Step 4) This page can typically be left as it is. Select Finish.
Custom Notification Settings
You can specify optional custom notificationSettings. If notificationSettings are not specified, then the app will use the default notification settings.
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.
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."