Skip to content

Native Initialization

The Alphyn SDK requires a two-step initialization process: native registration on iOS followed by Dart-side initialization.

On iOS, you must call AlphynSDK.register() synchronously in your AppDelegate.swift before Flutter starts. This registers background tasks with the iOS system. See the Platform Setup section for the full AppDelegate configuration.

import Alphyn
import Flutter
import UIKit
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// CRITICAL: Register background tasks BEFORE Flutter starts
do {
try AlphynSDK.register()
} catch {
print("AlphynSDK.register() failed: \(error.localizedDescription)")
}
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}

Important Notes:

  • AlphynSDK.register() must be called synchronously in didFinishLaunchingWithOptions before GeneratedPluginRegistrant.register()
  • Background task registration cannot be deferred to Dart code because iOS requires it during app launch
  • Ensure the import statement uses Alphyn (not AlphynSDK)

You should initialize the SDK in your Dart code, preferably in your main() function before running the app.

import 'package:alphyn_sdk/alphyn_sdk.dart';
import 'package:flutter/foundation.dart'; // kDebugMode
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the SDK. The debug hashes are development-only and each
// platform has its own, because a Flutter project registers as two
// separate Alphyn apps.
await AlphynSdk.initialize(
interval: 45.0,
androidDebugHash: kDebugMode ? 'YOUR_ANDROID_DEBUG_HASH' : null,
iosDebugHash: kDebugMode ? 'YOUR_IOS_DEBUG_HASH' : null,
);
runApp(const MyApp());
}

Parameters:

  • interval: Interval in seconds between security scans (e.g., 45.0 for 45 seconds). Defaults to 45.0.
  • androidDebugHash: optional development-only hash from the Alphyn Portal, applied only when running on Android
  • iosDebugHash: the same, applied only when running on iOS. Each platform is a separate Alphyn app with its own hashes. Do not ship either in production.