Skip to content

Add page to configure the main application #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions snippets/dart_snippets/lib/notification_plugin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'dart:async';

import 'package:dart_snippets/sdk_instance.dart';
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
// ANCHOR: init-sdk-app-group
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 APP_GROUP = 'group.com.example.application';
const String MNEMONIC_KEY = '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: APP_GROUP,
),
);
final String? mnemonic = await storage.read(key: MNEMONIC_KEY);
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);
}

static 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(
APP_GROUP,
);
if (sharedDirectory == null) {
throw Exception('Could not get shared directory');
}
path = sharedDirectory.path;
}
return "$path/breezSdkLiquid";
}
// ANCHOR_END: init-sdk-app-group
37 changes: 37 additions & 0 deletions snippets/react-native/notification_plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
defaultConfig,
connect,
LiquidNetwork,
} from '@breeztech/react-native-breez-sdk-liquid'
import { Platform } from "react-native"

// ANCHOR: init-sdk-app-group
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
let mnemonic = await SecureStorage.getItem(MNEMONIC_KEY, {
accessGroup: APP_GROUP,
accessible: ACCESSIBLE.AFTER_FIRST_UNLOCK,
})

// Create the default config, providing your Breez API key
let 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 })
}
// ANCHOR_END: init-sdk-app-group

31 changes: 31 additions & 0 deletions snippets/swift/BreezSDKExamples/Sources/NotificationPlugin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import BreezSDKLiquid

// ANCHOR: init-sdk-app-group
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 = 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
}
// ANCHOR_END: init-sdk-app-group
3 changes: 2 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
- [Setting up the foreground service](notifications/android_service.md)
- [Adding the notification plugin](notifications/android_plugin.md)
- [iOS](notifications/ios_setup.md)
- [Setting up the notification dervice extension](notifications/ios_service.md)
- [Setting up the notification service extension](notifications/ios_service.md)
- [Adding the notification plugin](notifications/ios_plugin.md)
- [Configuring the main application](notifications/ios_connect.md)
- [Advanced](notifications/advanced.md)
- [Adding logging](notifications/logging.md)
- [Changing default strings](notifications/changing_strings.md)
Expand Down
2 changes: 1 addition & 1 deletion src/notifications/android_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ class ExampleForegroundService : ForegroundService() {
```

## Reference implementation
For a complete reference, see how we implemented it in misty-breez wallet: [BreezFcmService.kt](https://github.com/breez/misty-breez/blob/main/android/app/src/main/kotlin/com/breez/liquid/l_breez/BreezFcmService.kt).
For a complete reference, see how we implemented it in Misty Breez: [BreezFcmService.kt](https://github.com/breez/misty-breez/blob/main/android/app/src/main/kotlin/com/breez/liquid/l_breez/BreezFcmService.kt).
34 changes: 34 additions & 0 deletions src/notifications/ios_connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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.

<custom-tabs category="lang">
<div slot="title">Swift</div>
<section>

```swift,ignore
{{#include ../../snippets/swift/BreezSDKExamples/Sources/NotificationPlugin.swift:init-sdk-app-group}}
```
</section>

<div slot="title">React Native</div>
<section>

```typescript
{{#include ../../snippets/react-native/notification_plugin.ts:init-sdk-app-group}}
```
</section>

<div slot="title">Dart</div>
<section>

```dart,ignore
{{#include ../../snippets/dart_snippets/lib/notification_plugin.dart:init-sdk-app-group}}
```
</section>
</custom-tabs>

## Reference implementation
For a complete reference, see how we implemented it in Misty Breez: [Config.dart](https://github.com/breez/misty-breez/blob/main/packages/breez_sdk_liquid/lib/src/model/config.dart).
4 changes: 2 additions & 2 deletions src/notifications/ios_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This Swift file should implement the Notification Plugin's `SDKNotificationServi

<div class="warning">
<h4>Developer note</h4>
When using the Notification Plugin on iOS, it is important to note that the <code>Config</code> <code>workingDir</code> needs to be set to the app group's shared directory in both the <code>NotificationService</code> target and in the main application target, whether that is a Swift, Flutter or React Native based application.
When using the Notification Plugin on iOS, it is important to note that the <code>Config</code> <code>workingDir</code> needs to be set to the app group's shared directory in both the <code>NotificationService</code> target and in the main application target, whether that is a Swift, Flutter or React Native based application. See <a href="ios_connect.html">Configuring the main application</a>.
</div>
<div class="warning">
<h4>Developer note</h4>
Expand Down Expand Up @@ -73,4 +73,4 @@ class NotificationService: SDKNotificationService {
```

## Reference implementation
For a complete reference, see how we implemented it in misty-breez wallet: [NotificationService.swift](https://github.com/breez/misty-breez/blob/main/ios/NotificationService/NotificationService.swift).
For a complete reference, see how we implemented it in Misty Breez: [NotificationService.swift](https://github.com/breez/misty-breez/blob/main/ios/NotificationService/NotificationService.swift).
1 change: 1 addition & 0 deletions src/notifications/ios_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ In order to add the Notification Plugin to your iOS application, first you need
## Next steps
- **[Setting up the Notification Service Extension](ios_service.md)**
- **[Adding the Notification Plugin](ios_plugin.md)**
- **[Configuring the main application](ios_connect.md)**
Loading