Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Configuring the main application

Once you've integrated the Notification Plugin into your NotificationService target, you need to update the main application to use the same configuration as the Notification Plugin. As the application is now using a shared application group identifier for both the main and NotificationService targets, we need to use the app group when accessing the keychain and to configure a shared working directory for the SDK.

Note: The mnemonic should also be stored to the same app group.

Swift
import KeychainAccess

fileprivate let SERVICE = "com.example.application"
fileprivate let APP_GROUP = "group.com.example.application"
fileprivate let MNEMONIC_KEY = "BREEZ_SDK_LIQUID_SEED_MNEMONIC"

func initSdk() throws -> BindingLiquidSdk? {
    // Read the mnemonic from secure storage using the app group
    let keychain = Keychain(service: SERVICE, accessGroup: APP_GROUP)
    guard let mnemonic = try? keychain.getString(MNEMONIC_KEY) else {
        return nil
    }

    // Create the default config, providing your Breez API key
    var config = try defaultConfig(network: LiquidNetwork.mainnet, breezApiKey: "<your-Breez-API-key>")

    // Set the working directory to the app group path
    config.workingDir = FileManager
        .default.containerURL(forSecurityApplicationGroupIdentifier: APP_GROUP)!
        .appendingPathComponent("breezSdkLiquid", isDirectory: true)
        .path

    let connectRequest = ConnectRequest(config: config, mnemonic: mnemonic)
    let sdk = try? connect(req: connectRequest)

    return sdk
}
React Native
import SecureStorage, { ACCESSIBLE } from 'react-native-secure-storage'
import * as RNFS from 'react-native-fs'

const APP_GROUP = 'group.com.example.application'
const MNEMONIC_KEY = 'BREEZ_SDK_LIQUID_SEED_MNEMONIC'

const initSdk = async () => {
  // Read the mnemonic from secure storage using the app group
  const mnemonic = await SecureStorage.getItem(MNEMONIC_KEY, {
    accessGroup: APP_GROUP,
    accessible: ACCESSIBLE.AFTER_FIRST_UNLOCK
  })

  // Create the default config, providing your Breez API key
  const config = await defaultConfig(
    LiquidNetwork.MAINNET,
    '<your-Breez-API-key>'
  )

  // Set the working directory to the app group path
  if (Platform.OS === 'ios') {
    const groupPath = await RNFS.pathForGroup(APP_GROUP)
    config.workingDir = `${groupPath}/breezSdkLiquid`
  }

  await connect({ mnemonic, config })
}
Dart
import 'package:app_group_directory/app_group_directory.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:path_provider/path_provider.dart';

const String appGroup = 'group.com.example.application';
const String mnemonicKey = 'BREEZ_SDK_LIQUID_SEED_MNEMONIC';

Future<void> initSdk() async {
  // Read the mnemonic from secure storage using the app group
  final FlutterSecureStorage storage = const FlutterSecureStorage(
    iOptions: IOSOptions(
      accessibility: KeychainAccessibility.first_unlock,
      groupId: appGroup,
    ),
  );
  final String? mnemonic = await storage.read(key: mnemonicKey);
  if (mnemonic == null) {
    throw Exception('Mnemonic not found');
  }

  // Create the default config, providing your Breez API key
  Config config = defaultConfig(network: LiquidNetwork.mainnet, breezApiKey: "<your-Breez-API-key>");
  
  // Set the working directory to the app group path
  config = config.copyWith(workingDir: await getWorkingDir());

  ConnectRequest connectRequest = ConnectRequest(mnemonic: mnemonic, config: config);

  await breezSDKLiquid.connect(req: connectRequest);
}

Future<String> getWorkingDir() async {
  String path = '';
  if (defaultTargetPlatform == TargetPlatform.android) {
    final Directory documentsDir = await getApplicationDocumentsDirectory();
    path = documentsDir.path;
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    final Directory? sharedDirectory = await AppGroupDirectory.getAppGroupDirectory(
      appGroup,
    );
    if (sharedDirectory == null) {
      throw Exception('Could not get shared directory');
    }
    path = sharedDirectory.path;
  }
  return "$path/breezSdkLiquid";
}

Reference implementation

For a complete reference, see how we implemented it in Misty Breez: Config.dart.