iOS Flutter platform not detected by license key
When you initialize Nutrient SDK with a license key in your Flutter iOS application, you may encounter a licensing error. This typically occurs because the Flutter platform isn’t properly detected during the initialization process.
Solution
A workaround for this issue is to set the license key directly in your iOS project’s native code instead of through the Flutter interface.
The license key must be set before Flutter is registered.
Read on to learn how to implement this.
-
Navigate to your Flutter iOS project’s
AppDelegate
file:-
For Swift projects (default) —
ios/Runner/AppDelegate.swift
-
For Objective-C projects —
ios/Runner/AppDelegate.m
-
-
Add the Nutrient license initialization code before the Flutter registration:
import UIKit import Flutter import PSPDFKit @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { // License key must be set before Flutter registration. let PSPDFSettingKeyHybridEnvironment = SDK.Setting(rawValue: "com.pspdfkit.hybrid-environment") let licenseKey = "YOUR_LICENSE_KEY" SDK.setLicenseKey(licenseKey, options: [PSPDFSettingKeyHybridEnvironment:"Flutter"]) // Flutter registration must come after license initialization. GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
#include "AppDelegate.h" #include "GeneratedPluginRegistrant.h" #import <PSPDFKit/PSPDFKit.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // License key must be set before Flutter registration. PSPDFSettingKey const PSPDFSettingKeyHybridEnvironment = @"com.pspdfkit.hybrid-environment"; NSString *licenseKey = @"YOUR_LICENSE_KEY"; [PSPDFKitGlobal setLicenseKey:licenseKey options:@{PSPDFSettingKeyHybridEnvironment: @"Flutter"}]; // Flutter registration must come after license initialization. [GeneratedPluginRegistrant registerWithRegistry:self]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } @end
Be sure to replace YOUR_LICENSE_KEY
with your actual Nutrient license key.
After implementing this solution, you should no longer set the license key through the Flutter interface so as to avoid duplicate initialization attempts.