SDK Configuration
Prerequisites
- The
altcraft_sdkpackage is added to the Flutter project. - Push notification provider SDKs are integrated into the application project.
- For Android, one or more providers are configured: FCM, HMS, RuStore.
- For iOS, one or more providers are configured: APNS, FCM, HMS.
- If API requests must be authorized via JWT, the JWT provider is registered on the native side of the application.
flutter pub add altcraft_sdk
flutter pub get
Application Preparation
Passing JWT Token to the SDK (Optional)
JWT implementation is required if JWT authentication of API requests is used. JWT confirms that user identifiers are authenticated by the application.
JWT authentication implementation is mandatory if a matching type other than push data from the subscription is used, such as email, phone, or internal user identifier.
In Flutter SDK, the JWT provider is not registered via the Dart API. It must be configured natively:
- Android: in
Application.onCreate; - iOS: in
AppDelegate.
Setup is performed similarly to the native platform SDKs: Android and iOS.
Preparing for Push Providers
Push provider setup is performed on the native side of the application.
Android:
iOS:
The Flutter package provides the Dart API and platform bridge. JWT registration, push provider registration, APNS/FCM/HMS/RuStore processing, and Notification Service Extension setup are performed in the native parts of the project.
SDK Initialization
Initialization Parameters
To pass configuration parameters, use the AltcraftConfig object:
const AltcraftConfig(
apiUrl: 'https://pxl-example.altcraft.com',
rToken: 'your-role-token',
appInfo: AppInfo(
appID: '1:000000000000:android:0000000000000000',
appIID: '00000000-0000-4000-8000-000000000000',
appVer: '1.0.0',
),
providerPriorityList: ['android-firebase'],
enableLogging: true,
)
Parameter description:
apiUrl String
Required: Yes
Description: Altcraft API endpoint URL.
rToken String?
Default: null
Required: No
Description: Role token for resource, database, or account identification.
appInfo AppInfo?
Default: null
Required: No
Description: Basic application metadata.
AppInfo fields:
| Field | Type | Description |
|---|---|---|
appID | String | Application identifier. |
appIID | String | Application installation identifier. |
appVer | String | Application version. |
providerPriorityList List<String>?
Default: null
Required: No
Description: Push provider priority list. Index 0 is the highest priority provider.
Example for Android:
providerPriorityList: ['android-firebase', 'android-huawei', 'android-rustore']
Example for iOS:
providerPriorityList: ['ios-apns', 'ios-firebase', 'ios-huawei']
enableLogging bool?
Default: null
Required: No
Description: Enables or disables SDK logging.
Android-only fields
The following AltcraftConfig fields apply only on Android:
| Field | Type | Description |
|---|---|---|
icon | int? | Notification icon resource ID. |
pushReceiverModules | List<String>? | Packages of modules with overridden PushReceiver. |
pushChannelName | String? | Push notification channel name. |
pushChannelDescription | String? | Push notification channel description. |
Performing Initialization
To initialize the SDK, use the initialize(config) function:
import 'package:altcraft_sdk/altcraft_sdk.dart';
import 'package:flutter/widgets.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await AltcraftSDK.initialize(
const AltcraftConfig(
apiUrl: 'https://pxl-example.altcraft.com',
appInfo: AppInfo(
appID: '1:000000000000:ios:0000000000000000',
appIID: '00000000-0000-4000-8000-000000000001',
appVer: '1.0.0',
),
providerPriorityList: ['ios-apns'],
),
);
runApp(const AppRoot());
}
class AppRoot extends StatelessWidget {
const AppRoot({super.key});
@override
Widget build(BuildContext context) {
return const Directionality(
textDirection: TextDirection.ltr,
child: SizedBox.shrink(),
);
}
}
Working with App Group and UserDefaults on iOS
For iOS, the SDK provides methods for setting the App Group and writing string values to UserDefaults. The setAppGroup() method is used only on iOS; on Android the call completes successfully without action.
import 'dart:io';
import 'package:altcraft_sdk/altcraft_sdk.dart';
Future<void> configureIosAppGroup() async {
if (!Platform.isIOS) return;
const String appGroup = 'group.altcraft.flutter.example';
await AltcraftSDK.setAppGroup(appGroup);
await AltcraftSDK.setUserDefaultsValue(
appGroup,
'altcraft_jwt',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtYXRjaGluZyI6ImVtYWlsIn0.signature',
);
}
The setUserDefaultsValue(suiteName, key, value) method is also available on Android, where suiteName is ignored and the value is saved to the SDK's SharedPreferences. The value parameter has type String?: a string writes the value, null removes the key. On iOS, suiteName must point to an available UserDefaults suite; if the suite is not found, the method will throw an AltcraftException with code ERR.
Requesting Notification Permission
For Android, use requestNotificationPermission():
import 'package:altcraft_sdk/altcraft_sdk.dart';
Future<bool> requestAndroidNotificationPermission() {
return AltcraftSDK.requestNotificationPermission();
}
The method returns true if permission is granted. On Android below version 13, permission is not required, so the method returns true. If the user denied, there is no active Activity, or a request error occurred, false is returned. On iOS, this Dart method does not request permission and returns false; iOS permissions are configured in the native part of the application.