Skip to main content
Use pnlight_sdk for Flutter apps that need PNLight on iOS.

Requirements

  • Flutter 3.3.0+
  • Dart 2.17.0 or later, below 4.0.0
  • iOS 12.0+

Install

Add the package:
flutter pub add pnlight_sdk
Package page: pnlight_sdk on pub.dev. Flutter SDK version

iOS setup

If you use RemoteUiView, add the DivKit CocoaPods source to ios/Podfile before other sources:
source 'https://github.com/divkit/divkit-ios.git'
If your app collects IDFA on iOS 14.0+, add NSUserTrackingUsageDescription to Info.plist:
<key>NSUserTrackingUsageDescription</key>
<string>This app uses device tracking to support attribution and analytics.</string>

Initialize the SDK

import 'package:pnlight_sdk/pnlight_sdk.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await PNLightSDK.initialize('pnlight_sdk_token');

  runApp(const MyApp());
}

Common calls

final success = await PNLightSDK.addAttribution(
  provider: 'appsFlyer',
  data: {'af_status': 'Non-organic'},
  identifier: 'appsFlyerCustomerId',
);

await PNLightSDK.logEvent('paywall_viewed', {
  'placement': 'paywall',
});
logEvent sends optional in-app events to PNLight. You can review them in Analytics → App Events, on the Events page, and in customer timelines.

IDFA after ATT

If PNLight initializes before the App Tracking Transparency prompt completes, call updateIdfa() after authorization so PNLight receives the granted IDFA.
import 'package:app_tracking_transparency/app_tracking_transparency.dart';
import 'package:pnlight_sdk/pnlight_sdk.dart';

await AppTrackingTransparency.requestTrackingAuthorization();
await PNLightSDK.updateIdfa();

Remote UI

import 'package:pnlight_sdk/pnlight_sdk.dart';

RemoteUiView(
  placement: 'paywall',
  cardId: 'paywall_card',
  ignoreCache: false,
  onAction: (RemoteUiActionEvent event) async {
    if (event.path == 'purchase') {
      final success = await startPurchase(event.params['id']);
      if (success) {
        openMainScreen();
      }
    }
  },
  onError: (Object error) {
    // Show a local fallback or close the screen.
  },
)
The Flutter package wraps the PNLight iOS SDK. Do not call PNLight SDK methods on unsupported platforms.