### Configure UnionadUserInfo instances Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/PrivacyAndUserInfo.md Examples for setting up user segmentation, minimal data, or GDPR-compliant tracking. ```dart UnionadUserInfo( userId: "user_12345", age: 35, gender: 1, // male channel: "app_store", subChannel: "organic", userValueGroup: "premium", customInfos: { "subscription": "premium", "region": "us-west-2", "game_level": "50", "spend_tier": "high", }, ) ``` ```dart UnionadUserInfo( userId: "device_${uuid.v4()}", gender: 2, // unknown channel: "direct", ) ``` ```dart UnionadUserInfo( userId: "anon_hash", // Hashed/pseudonymized ID age: null, // Not collected gender: 2, // Unknown channel: "direct", subChannel: null, userValueGroup: null, customInfos: {}, // No custom tracking ) ``` -------------------------------- ### Handle Full-Screen Video Events Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionadStream.md Example implementation for listening to full-screen video ad events. ```dart final StreamSubscription _adStream = FlutterUnionad.FlutterUnionadStream.initAdStream( flutterUnionadFullVideoCallBack: FlutterUnionadFullVideoCallBack( onShow: () => print("Full-screen shown"), onSkip: () => print("User skipped"), onFinish: () => print("Video completed"), onClose: () => print("Ad closed"), onFail: (error) => print("Failed: $error"), onClick: () => print("User clicked"), ), ); ``` -------------------------------- ### Configure IOSPrivacy instances Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/PrivacyAndUserInfo.md Examples for setting up privacy configurations for ATT compliance or regional requirements. ```dart IOSPrivacy( limitPersonalAds: false, // Will reflect user's ATT tracking preference limitProgrammaticAds: false, forbiddenCAID: false, ) ``` ```dart IOSPrivacy( limitPersonalAds: false, limitProgrammaticAds: false, forbiddenCAID: true, // Disable CAID for data sovereignty ) ``` -------------------------------- ### Configure AndroidPrivacy instances Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/PrivacyAndUserInfo.md Examples demonstrating how to initialize AndroidPrivacy for strict privacy or GDPR compliance scenarios. ```dart AndroidPrivacy( isCanUseLocation: false, lat: 0.0, lon: 0.0, isCanUsePhoneState: false, isCanUseWifiState: false, isCanUseAndroidId: false, alist: false, isLimitPersonalAds: true, isProgrammaticRecommend: false, userPrivacyConfig: { "mcod": "0", "installUninstallListen": "0", }, ) ``` ```dart AndroidPrivacy( isCanUseLocation: false, isCanUsePhoneState: false, isCanUseWifiState: true, isCanUseAndroidId: true, alist: false, isLimitPersonalAds: false, // Determined by user consent isProgrammaticRecommend: true, userPrivacyConfig: { "mcod": "1", "installUninstallListen": "0", }, ) ``` -------------------------------- ### Initialize FlutterUnionadBannerCallBack Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Callbacks.md Example usage of the banner callback container with event handlers. ```dart FlutterUnionadBannerCallBack( onShow: () => print("Banner shown"), onFail: (error) => print("Error: $error"), onDislike: (reason) => print("Disliked: $reason"), onClick: () => print("User clicked"), onEcpm: (info) => print("eCPM: ${info?['ecpm']}"), ) ``` -------------------------------- ### Register SDK Configuration Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Defines the method signature for initializing the SDK and provides a usage example with common configuration parameters. ```dart static Future register({ required String iosAppId, required String androidAppId, String? ohosAppId, String? appName, bool? useMediation, bool? paid, String? keywords, bool? useTextureView, bool? allowShowNotify, bool? debug, bool? supportMultiProcess, int? themeStatus, List? directDownloadNetworkType, AndroidPrivacy? androidPrivacy, IOSPrivacy? iosPrivacy, UnionadUserInfo? userInfo, String? localConfig, }) async ``` ```dart await FlutterUnionad.register( androidAppId: "5098580", iosAppId: "5098580", appName: "unionad_test", useMediation: true, debug: true, themeStatus: FlutterUnionAdTheme.DAY, androidPrivacy: AndroidPrivacy( isCanUseLocation: false, lat: 0.0, lon: 0.0, ), iosPrivacy: IOSPrivacy( limitPersonalAds: false, ), userInfo: UnionadUserInfo( userId: "unionad_123", age: 19, gender: 2, channel: "flutter", ), ); ``` -------------------------------- ### Initialize FlutterUnionadPermissionCallBack Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Callbacks.md Example usage of the permission callback constructor to handle different permission outcomes. ```dart FlutterUnionadPermissionCallBack( notDetermined: () => print("Status unknown"), restricted: () => print("Restricted by system"), denied: () => print("User denied"), authorized: () => print("User authorized"), ) ``` -------------------------------- ### Implement FlutterUnionadBannerView Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/AdViews.md Example usage of the banner view with specific ad IDs and event callbacks. ```dart FlutterUnionadBannerView( androidCodeId: "102735527", iosCodeId: "102735527", width: 600.5, height: 120.5, callBack: FlutterUnionadBannerCallBack( onShow: () => print("Banner loaded"), onFail: (error) => print("Banner failed: $error"), onClick: () => print("Banner clicked"), onDislike: (message) => print("User dislikes banner"), ), ) ``` -------------------------------- ### Handle Interstitial Video Events Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionadStream.md Example implementation for listening to template-rendered interstitial ad events. ```dart final StreamSubscription _adStream = FlutterUnionad.FlutterUnionadStream.initAdStream( flutterUnionadNewInteractionCallBack: FlutterUnionadNewInteractionCallBack( onShow: () => print("Interstitial shown"), onClose: () => print("Interstitial closed"), onFail: (error) => print("Failed: $error"), onClick: () => print("User clicked"), onSkip: () => print("User skipped"), onFinish: () => print("Ad finished"), onReady: () async { print("Ready to show"); await FlutterUnionad.showFullScreenVideoAdInteraction(); }, onUnReady: () => print("Not ready yet"), onEcpm: (info) => print("eCPM: ${info?['ecpm']}"), ), ); ``` -------------------------------- ### Handle Rewarded Video Events Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionadStream.md Example implementation for listening to rewarded video ad events and managing the stream lifecycle. ```dart final StreamSubscription _adStream = FlutterUnionad.FlutterUnionadStream.initAdStream( flutterUnionadRewardAdCallBack: FlutterUnionadRewardAdCallBack( onShow: () { print("Reward ad shown"); }, onClick: () { print("User clicked"); }, onFail: (error) { print("Failed: $error"); }, onClose: () { print("Ad closed"); }, onSkip: () { print("User skipped"); }, onVerify: (verified, amount, name, code, error) { if (verified) { // Grant reward print("Reward granted: $amount $name"); } else { // Fraud detected print("Reward denied: $error"); } }, onRewardArrived: (verified, type, amount, name, code, error, propose) { // Advanced reward verification with proposal print("Advanced: type=$type, verified=$verified, proposed=$propose"); }, onReady: () async { print("Preload ready"); await FlutterUnionad.showRewardVideoAd(); }, onUnReady: () { print("Preload not ready yet"); }, onCache: () { print("Media cached - safe to show"); }, ), ); // Clean up when done @override void dispose() { _adStream.cancel(); super.dispose(); } ``` -------------------------------- ### Request Permissions Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Defines the method for requesting platform-specific permissions and provides a callback-based implementation example. ```dart static Future requestPermissionIfNecessary( {FlutterUnionadPermissionCallBack? callBack} ) async ``` ```dart FlutterUnionad.requestPermissionIfNecessary( callBack: FlutterUnionadPermissionCallBack( notDetermined: () { print("Permission status undetermined"); }, restricted: () { print("Permission is restricted"); }, denied: () { print("Permission denied by user"); }, authorized: () { print("Permission authorized"); }, ), ); ``` -------------------------------- ### iOS AppDelegate Setup for Ad Click Handling (Objective-C) Source: https://github.com/gstory0404/flutter_unionad/blob/master/notice.md For versions 1.3.10 and later, this Objective-C code in AppDelegate.m is required for splash ads to be clickable on iOS. ```objectivec @interface AppDelegate() @property (nonatomic, strong) UINavigationController *navigationController; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self]; FlutterViewController *controller = (FlutterViewController*)self.window.rootViewController; self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller]; self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = self.navigationController; [self.navigationController setNavigationBarHidden:YES animated:YES]; [self.window makeKeyAndVisible]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; } ``` ``` -------------------------------- ### Implementing FlutterUnionadDrawFeedAdView Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/AdViews.md Example usage of the widget with a full set of event callbacks to monitor ad lifecycle and user interaction. ```dart FlutterUnionadDrawFeedAdView( androidCodeId: "102734241", iosCodeId: "102734241", width: 600.5, height: 800.5, isMuted: true, callBack: FlutterUnionadDrawFeedCallBack( onShow: () => print("Draw ad shown"), onFail: (error) => print("Draw ad failed: $error"), onClick: () => print("Draw ad clicked"), onDislike: (message) => print("Disliked: $message"), onVideoPlay: () => print("Video started"), onVideoPause: () => print("Video paused"), onVideoStop: () => print("Video ended"), ), ) ``` -------------------------------- ### iOS AppDelegate Setup for Ad Click Handling (Swift) Source: https://github.com/gstory0404/flutter_unionad/blob/master/notice.md For versions 1.3.10 and later, this Swift code in AppDelegate.swift is required for splash ads to be clickable on iOS. ```swift @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { var navigationController : UINavigationController? = nil override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self) let controller = self.window.rootViewController as! FlutterViewController self.navigationController = UINavigationController.init(rootViewController: controller) self.window = UIWindow.init(frame: UIScreen.main.bounds) self.window.rootViewController = self.navigationController; self.navigationController?.setNavigationBarHidden(true, animated: true) self.window.makeKeyAndVisible() return super.application(application, didFinishLaunchingWithOptions: launchOptions) } } ``` -------------------------------- ### Implementing FlutterUnionadNativeAdView Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/AdViews.md Example usage of the native ad view widget with event callbacks for tracking ad interactions. ```dart FlutterUnionadNativeAdView( androidCodeId: "102730271", iosCodeId: "102730271", supportDeepLink: true, width: 375.5, height: 0, // Auto height isMuted: true, callBack: FlutterUnionadNativeCallBack( onShow: () => print("Native ad shown"), onFail: (error) => print("Native ad failed: $error"), onDislike: (message) => print("User dislikes: $message"), onClick: () => print("Native ad clicked"), ), ) ``` -------------------------------- ### Import flutter_unionad Plugin Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md Import the flutter_unionad plugin into your Dart file to start using its functionalities. ```Dart import 'package:flutter_unionad/flutter_unionad.dart'; ``` -------------------------------- ### Android Permissions Configuration for UnionAd SDK Source: https://github.com/gstory0404/flutter_unionad/blob/master/notice.md Starting from plugin version 1.2.2, Android requires manual configuration of permissions for the UnionAd SDK. This includes necessary, optional, and demo-specific permissions. ```xml ``` -------------------------------- ### View project file structure Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/README.md Displays the directory layout of the documentation repository. ```text output/ ├── README.md (this file) ├── INDEX.md (complete index & navigation) ├── OVERVIEW.md (architecture & platform details) ├── QUICK_START.md (10 copy-paste examples) ├── configuration.md (initialization parameters) ├── types.md (type definitions) └── api-reference/ ├── FlutterUnionad.md (main SDK class) ├── AdViews.md (4 widget types) ├── Callbacks.md (9 callback classes + typedefs) ├── FlutterUnionadStream.md (event streaming) ├── PrivacyAndUserInfo.md (privacy & user config) └── Constants.md (8 constant classes) ``` -------------------------------- ### Configure Theme and UI Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Visual and notification settings for the SDK. ```dart themeStatus: FlutterUnionAdTheme.NIGHT, allowShowNotify: true, ``` -------------------------------- ### Initialize SDK and Display Banner Ad Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/OVERVIEW.md Registers the SDK during initialization and renders a banner ad view within the widget tree. ```dart void initState() { super.initState(); _initializeSDK(); } Future _initializeSDK() async { await FlutterUnionad.register( androidAppId: "5098580", iosAppId: "5098580", appName: "My App", ); } @override Widget build(BuildContext context) { return FlutterUnionadBannerView( androidCodeId: "102735527", iosCodeId: "102735527", width: 300, height: 50, callBack: FlutterUnionadBannerCallBack( onShow: () => print("Banner shown"), onFail: (e) => print("Banner failed: $e"), ), ); } ``` -------------------------------- ### Manage Ad Theme Settings Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Configure the ad theme during initialization and retrieve or update the theme status dynamically. ```dart // Set theme at init await FlutterUnionad.register( // ... themeStatus: FlutterUnionAdTheme.NIGHT, ); // Get current theme int theme = await FlutterUnionad.getThemeStatus(); // Switch theme later await FlutterUnionad.register( // ... (all params) themeStatus: FlutterUnionAdTheme.DAY, ); ``` -------------------------------- ### Initialize the SDK Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Call the register method to initialize the SDK with your application IDs. Ensure this is awaited during app startup. ```dart await FlutterUnionad.register( androidAppId: "5098580", iosAppId: "5098580", appName: "My App", debug: true, ); ``` -------------------------------- ### Retrieve SDK Version Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Demonstrates how to fetch and print the current version of the native Pangle SDK. ```dart static Future getSDKVersion() async ``` ```dart String version = await FlutterUnionad.getSDKVersion(); print("SDK Version: $version"); ``` -------------------------------- ### Get Theme Status Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Retrieves the current theme mode, returning 0 for day and 1 for night. ```dart static Future getThemeStatus() async ``` ```dart int themeMode = await FlutterUnionad.getThemeStatus(); if (themeMode == FlutterUnionAdTheme.NIGHT) { print("Night theme active"); } ``` -------------------------------- ### Manage ad themes Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Constants.md Shows how to set the theme during registration, retrieve the current status, and update the theme dynamically. ```dart await FlutterUnionad.register( // ... themeStatus: FlutterUnionAdTheme.DAY, // or NIGHT ); ``` ```dart int currentTheme = await FlutterUnionad.getThemeStatus(); if (currentTheme == FlutterUnionAdTheme.NIGHT) { print("Dark mode active"); } ``` ```dart // User enables dark mode await FlutterUnionad.register( // ... (all required params) themeStatus: FlutterUnionAdTheme.NIGHT, ); ``` -------------------------------- ### Copy .ohpmrc for鸿蒙next Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md For鸿蒙next projects, copy the .ohpmrc file to your project's root directory to ensure proper integration. ```Shell [.ohpmrc](example/ohos/.ohpmrc) ``` -------------------------------- ### Theme Management Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Methods to initialize and update the SDK theme status. ```APIDOC ## FlutterUnionad.register ### Description Initializes the SDK with specific theme settings. ### Parameters - **themeStatus** (FlutterUnionAdTheme) - Required - The theme mode (e.g., FlutterUnionAdTheme.NIGHT, FlutterUnionAdTheme.DAY). ## FlutterUnionad.getThemeStatus ### Description Retrieves the current theme status of the SDK. ### Returns - **int** - The current theme status code. ``` -------------------------------- ### Get Flutter UnionAd SDK Version Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md Retrieves the current version of the Flutter UnionAd SDK. This is a simple utility function. ```dart await FlutterUnionad.getSDKVersion(); ``` -------------------------------- ### FlutterUnionad.register() Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Initializes the Pangle SDK with the required application IDs and optional configuration settings. ```APIDOC ## FlutterUnionad.register() ### Description Initializes the Pangle SDK. This method must be called to configure the SDK before requesting any ads. ### Method Dart Method ### Signature `await FlutterUnionad.register({required String iosAppId, required String androidAppId, String? ohosAppId, String? appName, bool? useMediation, bool? paid, String? keywords, bool? useTextureView, bool? allowShowNotify, bool? debug, bool? supportMultiProcess, int? themeStatus, List? directDownloadNetworkType, AndroidPrivacy? androidPrivacy, IOSPrivacy? iosPrivacy, UnionadUserInfo? userInfo, String? localConfig})` ### Parameters - **androidAppId** (String) - Required - Pangle App ID for Android platform. - **iosAppId** (String) - Required - Pangle App ID for iOS platform. - **ohosAppId** (String) - Optional - Pangle App ID for HarmonyOS platform. - **appName** (String) - Optional - Application display name. - **debug** (bool) - Optional - Enable verbose debug logging. - **useMediation** (bool) - Optional - Enable GroMore mediation. - **supportMultiProcess** (bool) - Optional - Enable multi-process support. - **paid** (bool) - Optional - Indicate if user is a paying customer. - **keywords** (String) - Optional - Comma-separated targeting keywords. - **userInfo** (UnionadUserInfo) - Optional - User segmentation data. - **themeStatus** (int) - Optional - Theme mode (0=DAY, 1=NIGHT). - **allowShowNotify** (bool) - Optional - Allow notification bar prompts. - **useTextureView** (bool) - Optional - Use TextureView for Android video rendering. - **directDownloadNetworkType** (List) - Optional - Network types allowing direct downloads. ``` -------------------------------- ### Configure iOS Info.plist Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Add necessary keys to Info.plist to enable embedded views and allow arbitrary network loads. ```xml io.flutter.embedded_views_preview NSAppTransportSecurity NSAllowsArbitraryLoads ``` -------------------------------- ### Configure Download Behavior in Ad Widgets Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Constants.md Passes the download type configuration to supported ad widgets. ```dart FlutterUnionadBannerView( androidCodeId: "102735527", iosCodeId: "102735527", // ... other params ... // downloadType: FlutterUnionadDownLoadType.DOWNLOAD_TYPE_POPUP, ) ``` -------------------------------- ### Configure General Settings Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Settings for application identification, debugging, and mediation behavior. ```dart appName: "My App", debug: true, useMediation: true, supportMultiProcess: false, ``` -------------------------------- ### Initialize FlutterUnionad SDK Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Register the SDK with required app IDs, user information, privacy settings, and configuration options. ```dart await FlutterUnionad.register( // Required app IDs androidAppId: "5098580", iosAppId: "5098580", // App info appName: "My App", // Feature toggles useMediation: true, debug: true, allowShowNotify: true, supportMultiProcess: false, // User data paid: false, keywords: "gaming,entertainment,news", userInfo: UnionadUserInfo( userId: "device_id_123", age: 28, gender: 1, channel: "app_store", subChannel: "organic", userValueGroup: "standard", customInfos: { "tier": "free", "region": "US_WEST", }, ), // UI/Theme themeStatus: FlutterUnionAdTheme.DAY, // Network directDownloadNetworkType: [ FlutterUnionadNetCode.NETWORK_STATE_WIFI, FlutterUnionadNetCode.NETWORK_STATE_4G, ], // Privacy - Android androidPrivacy: AndroidPrivacy( isCanUseLocation: false, lat: 37.7749, lon: -122.4194, isCanUsePhoneState: false, isCanUseWifiState: true, isCanUseAndroidId: true, isLimitPersonalAds: false, isProgrammaticRecommend: true, userPrivacyConfig: { "mcod": "1", "installUninstallListen": "0", }, ), // Privacy - iOS iosPrivacy: IOSPrivacy( limitPersonalAds: false, limitProgrammaticAds: false, forbiddenCAID: false, ), // Fallback config localConfig: "site_config_5098580", ); ``` -------------------------------- ### Apply ad load types Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Constants.md Demonstrates passing load types to splash screen widgets and reward video ad loading methods. ```dart // Real-time load for splash screen (on-demand) FlutterUnionadSplashAdView( androidCodeId: "102729400", iosCodeId: "102729400", // adLoadType: FlutterUnionadLoadType.LOAD, ) // Preload for video placement (cache ahead of time) await FlutterUnionad.loadRewardVideoAd( androidCodeId: "102733764", iosCodeId: "102733764", // Inherently PRELOAD by design ) ``` -------------------------------- ### Configure Network Settings Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Define network types allowed for direct app downloads. ```dart directDownloadNetworkType: [ FlutterUnionadNetCode.NETWORK_STATE_WIFI, FlutterUnionadNetCode.NETWORK_STATE_4G, ], ``` -------------------------------- ### Configure Application IDs Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Required platform-specific App IDs obtained from the Pangle admin console. ```dart androidAppId: "5098580", iosAppId: "5098580", ``` -------------------------------- ### Initialize Flutter UnionAd SDK Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md Call this method to initialize the SDK. It requires app IDs for Android and iOS, app name, and configuration for mediation, privacy settings, and user information. Re-calling this method is necessary if personalization settings are modified. ```dart await FlutterUnionad.register( //穿山甲广告 Android appid 必填 androidAppId: "5098580", //穿山甲广告 ios appid 必填 iosAppId: "5098580", //appname 必填 appName: "unionad_test", //使用聚合功能一定要打开此开关,否则不会请求聚合广告,默认这个值为false //true使用GroMore下的广告位 //false使用广告变现下的广告位 useMediation: true, //是否为计费用户 选填 paid: false, //用户画像的关键词列表 选填 keywords: "", //是否允许sdk展示通知栏提示 选填 allowShowNotify: true, //是否显示debug日志 debug: true, //是否支持多进程 选填 supportMultiProcess: false, //主题模式 默认FlutterUnionAdTheme.DAY,修改后需重新调用初始化 themeStatus: _themeStatus, //允许直接下载的网络状态集合 选填 directDownloadNetworkType: [ FlutterUnionadNetCode.NETWORK_STATE_2G, FlutterUnionadNetCode.NETWORK_STATE_3G, FlutterUnionadNetCode.NETWORK_STATE_4G, FlutterUnionadNetCode.NETWORK_STATE_WIFI ], androidPrivacy: AndroidPrivacy( //是否允许SDK主动使用地理位置信息 true可以获取,false禁止获取。默认为true isCanUseLocation: false, //当isCanUseLocation=false时,可传入地理位置信息,穿山甲sdk使用您传入的地理位置信息lat lat: 0.0, //当isCanUseLocation=false时,可传入地理位置信息,穿山甲sdk使用您传入的地理位置信息lon lon: 0.0, // 是否允许SDK主动使用手机硬件参数,如:imei isCanUsePhoneState: false, //当isCanUsePhoneState=false时,可传入imei信息,穿山甲sdk使用您传入的imei信息 imei: "", // 是否允许SDK主动使用ACCESS_WIFI_STATE权限 isCanUseWifiState: false, // 当isCanUseWifiState=false时,可传入Mac地址信息 macAddress: "", // 是否允许SDK主动使用WRITE_EXTERNAL_STORAGE权限 isCanUseWriteExternal: false, // 开发者可以传入oaid oaid: "b69cd3cf68900323", // 是否允许SDK主动获取设备上应用安装列表的采集权限 alist: false, // 是否能获取android ID isCanUseAndroidId: false, // 开发者可以传入android ID androidId: "", // 是否允许SDK在申明和授权了的情况下使用录音权限 isCanUsePermissionRecordAudio: false, // 是否限制个性化推荐接口 isLimitPersonalAds: false, // 是否启用程序化广告推荐 true启用 false不启用 isProgrammaticRecommend: false, userPrivacyConfig: { //控制oaid获取频率,"0"表示关闭,“1"或者其他值表示打开。 "mcod":"0", //关闭后台监听应用安装、更新、卸载行为 "installUninstallListen": "0", } ), iosPrivacy: IOSPrivacy( //允许个性化广告 limitPersonalAds: false, //允许程序化广告 limitProgrammaticAds: false, //允许CAID forbiddenCAID: false, ), //流量分组 userInfo: UnionadUserInfo( //设备ID。由开发者定义并传入聚合SDK,后续M支持基于设备ID维度统计数据、或针对个别设备进行测试 userId: "unionad_123", //年龄 age: 19, //性别 0女 1男 2未知 3不使用 gender: 2, //渠道。建议使用以下字符规则:大小写字母数字和下划线[A-Za-z0-9_] channel: "flutter", //子渠道。建议使用以下字符规则:大小写字母数字和下划线[A-Za-z0-9_] subChannel: "flutter_unionad", //分组 userValueGroup: "QQ", //自定义参数 Map customInfos: { "QQ": "123", "WeChat": "456", } ), //配置拉取失败时导入本地配置 https://www.csjplatform.com/supportcenter/5885 //android导入/android/app/src/main/assets/下,文件必须为json文件,传入文件名 //ios导入/ios/下,文件必须为json文件,传入文件名 localConfig: "site_config_5098580", ); ``` -------------------------------- ### Callback Methods Reference Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Reference for callback interfaces used to monitor ad events across different ad formats. ```APIDOC ## Callback Interfaces ### Widget Callbacks - **FlutterUnionadBannerCallBack**: onShow, onFail, onClick, onDislike, onEcpm - **FlutterUnionadSplashCallBack**: onShow, onFail, onClick, onFinish, onSkip, onTimeOut, onEcpm - **FlutterUnionadNativeCallBack**: onShow, onFail, onClick, onDislike, onEcpm - **FlutterUnionadDrawFeedCallBack**: onShow, onFail, onClick, onDislike, onVideoPlay, onVideoPause, onVideoStop, onEcpm ### Stream Callbacks - **FlutterUnionadRewardAdCallBack**: onShow, onClose, onFail, onClick, onSkip, onVerify, onRewardArrived, onReady, onUnReady, onCache, onEcpm - **FlutterUnionadNewInteractionCallBack**: onShow, onClose, onFail, onClick, onSkip, onFinish, onReady, onUnReady, onEcpm ``` -------------------------------- ### showRewardVideoAd Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Displays a preloaded rewarded video ad. ```APIDOC ## showRewardVideoAd ### Description Displays a preloaded rewarded video ad. Must call loadRewardVideoAd first. ### Return Value Returns Future indicating if the ad was shown successfully. ``` -------------------------------- ### Configure User Information Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Targeting parameters and user segmentation data to improve ad quality. ```dart paid: false, keywords: "gaming,entertainment", userInfo: UnionadUserInfo( userId: "user_123", age: 25, gender: 1, channel: "organic", subChannel: "app_store", userValueGroup: "premium", customInfos: { "subscription": "active", "region": "US", }, ), ``` -------------------------------- ### iOS Info.plist Configuration Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md For iOS, add specific keys to your Info.plist file to enable embedded views preview and allow arbitrary loads for network security, as required by the PlatformView usage. ```Objective-C io.flutter.embedded_views_preview NSAppTransportSecurity NSAllowsArbitraryLoads ``` -------------------------------- ### loadRewardVideoAd Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Preloads a rewarded video ad for later display. ```APIDOC ## loadRewardVideoAd ### Description Preloads a rewarded video ad for later display. ### Parameters - **androidCodeId** (String) - Required - Android rewarded ad code ID - **iosCodeId** (String) - Required - iOS rewarded ad code ID - **ohosCodeId** (String) - Optional - HarmonyOS rewarded ad code ID - **rewardName** (String) - Required - Name of the reward (e.g., "200 coins") - **rewardAmount** (int) - Required - Number of reward units - **userID** (String) - Required - Unique user identifier for tracking - **orientation** (int) - Optional - Video orientation (VERTICAL=1, HORIZONTAL=2) - **mediaExtra** (String) - Optional - Extra parameters to pass to backend - **mutedIfCan** (bool) - Optional - true: mute by default, false: unmuted ### Return Value Returns Future indicating if preload was initiated successfully. ``` -------------------------------- ### Configure Privacy Settings during Initialization Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/OVERVIEW.md Registers the SDK with specific privacy constraints for Android and iOS platforms. ```dart await FlutterUnionad.register( androidAppId: "5098580", iosAppId: "5098580", androidPrivacy: AndroidPrivacy( isCanUseLocation: false, isCanUsePhoneState: false, isCanUseAndroidId: true, isLimitPersonalAds: !userConsent, ), iosPrivacy: IOSPrivacy( limitPersonalAds: !userConsent, ), ); ``` -------------------------------- ### Define Full-Screen Video Ad Callbacks Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Callbacks.md Use this class to manage full-screen video ad events such as display, skip, close, and completion. ```dart class FlutterUnionadFullVideoCallBack { OnShow? onShow; OnClick? onClick; OnSkip? onSkip; OnClose? onClose; OnFail? onFail; OnFinish? onFinish; FlutterUnionadFullVideoCallBack({ this.onShow, this.onClick, this.onSkip, this.onClose, this.onFail, this.onFinish, }); } ``` -------------------------------- ### Implement Non-Widget Ad Stream Events Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/OVERVIEW.md Initialize a stream subscription for full-screen ads and ensure the subscription is cancelled in the dispose method to prevent memory leaks. ```dart final StreamSubscription sub = FlutterUnionad.FlutterUnionadStream.initAdStream( flutterUnionadRewardAdCallBack: FlutterUnionadRewardAdCallBack( onShow: () { ... }, onVerify: (verified, amount, name, code, error) { ... }, // ... other callbacks ), ); @override void dispose() { sub.cancel(); super.dispose(); } ``` -------------------------------- ### Implement Widget-Based Ad Callbacks Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/OVERVIEW.md Use callback objects within the ad widget constructor to handle lifecycle and interaction events for banner-style ads. ```dart FlutterUnionadBannerView( // ... callBack: FlutterUnionadBannerCallBack( onShow: () { ... }, onFail: (error) { ... }, onClick: () { ... }, onDislike: (message) { ... }, onEcpm: (info) { ... }, ), ) ``` -------------------------------- ### Configure Android Manifest Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/configuration.md Add required attributes to the AndroidManifest.xml file to support network traffic and resource replacement. ```xml ``` -------------------------------- ### Initialize Ad Stream Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionadStream.md Method signature for initializing the broadcast stream listener. ```dart static StreamSubscription initAdStream({ FlutterUnionadFullVideoCallBack? flutterUnionadFullVideoCallBack, FlutterUnionadInteractionCallBack? flutterUnionadInteractionCallBack, FlutterUnionadNewInteractionCallBack? flutterUnionadNewInteractionCallBack, FlutterUnionadRewardAdCallBack? flutterUnionadRewardAdCallBack, }) ``` -------------------------------- ### FlutterUnionad.register Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Initializes and registers the SDK with required configuration. This method must be called before displaying any ads. ```APIDOC ## static Future register({required String iosAppId, required String androidAppId, ...}) ### Description Initializes and registers the SDK with required configuration. Must be called before displaying any ads. ### Parameters - **iosAppId** (String) - Required - Pangle App ID for iOS platform - **androidAppId** (String) - Required - Pangle App ID for Android platform - **ohosAppId** (String) - Optional - Pangle App ID for HarmonyOS platform - **appName** (String) - Optional - Application name - **useMediation** (bool) - Optional - Enable GroMore aggregation (true for GroMore, false for direct monetization) - **paid** (bool) - Optional - Whether the user is a paying user - **keywords** (String) - Optional - User profile keywords for personalization - **useTextureView** (bool) - Optional - Use TextureView for rendering (Android-specific) - **allowShowNotify** (bool) - Optional - Allow SDK to show notification bar prompts - **debug** (bool) - Optional - Enable debug logging - **supportMultiProcess** (bool) - Optional - Enable multi-process support - **themeStatus** (int) - Optional - Theme mode (DAY=0, NIGHT=1) - **directDownloadNetworkType** (List) - Optional - Network types allowing direct downloads - **androidPrivacy** (AndroidPrivacy) - Optional - Android privacy configuration - **iosPrivacy** (IOSPrivacy) - Optional - iOS privacy configuration - **userInfo** (UnionadUserInfo) - Optional - User segmentation and custom info - **localConfig** (String) - Optional - Local config filename (json) for fallback when remote config fails ### Return Value Returns a Future indicating success or failure of initialization. ``` -------------------------------- ### Stream Lifecycle Management Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Initialize ad streams in initState and ensure they are cancelled in dispose to prevent memory leaks. ```dart late StreamSubscription _adStream; @override void initState() { _adStream = FlutterUnionad.FlutterUnionadStream.initAdStream(...); } @override void dispose() { _adStream.cancel(); super.dispose(); } ``` -------------------------------- ### Default network state configuration Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/Constants.md The default list of network types enabled for direct downloads. ```dart [ FlutterUnionadNetCode.NETWORK_STATE_MOBILE, FlutterUnionadNetCode.NETWORK_STATE_2G, FlutterUnionadNetCode.NETWORK_STATE_3G, FlutterUnionadNetCode.NETWORK_STATE_4G, FlutterUnionadNetCode.NETWORK_STATE_WIFI, ] ``` -------------------------------- ### Ad Error Handling Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Implement the onFail callback to handle ad loading errors and update UI state accordingly. ```dart FlutterUnionadBannerView( // ... callBack: FlutterUnionadBannerCallBack( onFail: (error) { setState(() => _showFallback = true); debugPrint("Ad error: $error"); }, ), ) ``` -------------------------------- ### Enable Debug Logging Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/QUICK_START.md Set the debug flag to true during initialization to enable verbose logging for development. ```dart await FlutterUnionad.register( // ... debug: true, ); ``` -------------------------------- ### Listen to Rewarded Video Ad Events Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md Initialize a stream to listen for rewarded video ad events using FlutterUnionadStream.initAdStream. This includes callbacks for ad show, click, failure, close, skip, verification, readiness, material caching, and unreadiness. ```Dart FlutterUnionad.FlutterUnionadStream.initAdStream( //激励广告 flutterUnionadRewardAdCallBack: FlutterUnionadRewardAdCallBack( onShow: (){ print("激励广告显示"); }, onClick: (){ print("激励广告点击"); }, onFail: (error){ print("激励广告失败 $error"); }, onClose: (){ print("激励广告关闭"); }, onSkip: (){ print("激励广告跳过"); }, onVerify: (rewardVerify,rewardAmount,rewardName){ print("激励广告奖励 $rewardVerify $rewardAmount $rewardName"); }, onReady: () async{ print("激励广告预加载准备就绪"); await FlutterUnionad.showRewardVideoAd(); }, onCache: () async { print("激励广告物料缓存成功。建议在这里进行广告展示,可保证播放流畅和展示流畅,用户体验更好。"); }, onUnReady: (){ print("激励广告预加载未准备就绪"); }, onRewardArrived: (rewardVerify, rewardType, rewardAmount, rewardName, errorCode, error, propose) { print( "阶段激励广告奖励 验证结果=$rewardVerify 奖励类型=$rewardType 奖励=$rewardAmount" "奖励名称$rewardName 错误码=$errorCode 错误$error 建议奖励$propose"); }), ), ); ``` -------------------------------- ### Show Full-Screen Video Ad Interaction Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Displays a preloaded full-screen video interstitial ad. Returns a boolean indicating success. ```dart static Future showFullScreenVideoAdInteraction() async ``` ```dart bool shown = await FlutterUnionad.showFullScreenVideoAdInteraction(); if (shown) { print("Full-screen ad displayed"); } ``` -------------------------------- ### Implement Rewarded Video with Stream Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/OVERVIEW.md Manages rewarded video ad lifecycle using a stream subscription, including preloading and handling reward verification. ```dart late StreamSubscription _adStream; @override void initState() { super.initState(); _initStream(); } void _initStream() { _adStream = FlutterUnionad.FlutterUnionadStream.initAdStream( flutterUnionadRewardAdCallBack: FlutterUnionadRewardAdCallBack( onReady: () async { print("Ready to show"); await FlutterUnionad.showRewardVideoAd(); }, onVerify: (verified, amount, name, code, error) { if (verified) { setState(() => coins += amount); } }, ), ); } void _preloadRewardAd() async { await FlutterUnionad.loadRewardVideoAd( androidCodeId: "102733764", iosCodeId: "102733764", rewardName: "coins", rewardAmount: 100, userID: "user123", ); } @override void dispose() { _adStream.cancel(); super.dispose(); } ``` -------------------------------- ### Android Manifest Configuration Source: https://github.com/gstory0404/flutter_unionad/blob/master/README.md Configure the AndroidManifest.xml file in your Android project to enable cleartext traffic and replace the default label. The SDK is already configured within the plugin. ```Java ``` -------------------------------- ### showFullScreenVideoAdInteraction Source: https://github.com/gstory0404/flutter_unionad/blob/master/_autodocs/api-reference/FlutterUnionad.md Displays a preloaded full-screen video interstitial ad. ```APIDOC ## showFullScreenVideoAdInteraction ### Description Displays a preloaded full-screen video interstitial ad. ### Signature `static Future showFullScreenVideoAdInteraction() async` ### Return Value Returns `Future` indicating if the ad was shown. ### Example ```dart bool shown = await FlutterUnionad.showFullScreenVideoAdInteraction(); if (shown) { print("Full-screen ad displayed"); } ``` ```