import 'dart:io'; import 'package:flutter/services.dart'; import 'package:union_ad_ssgf/event/ad_event_handler.dart'; import 'union_ad_ssgf_platform_interface.dart'; /// 三商共富 Flutter 广告插件 class UnionAdSsgf { /// 方法通道 static const MethodChannel _methodChannel = MethodChannel('union_ad_ssgf_method'); /// 事件通道 static const EventChannel _eventChannel = EventChannel('union_ad_ssgf_event'); /// 请求应用跟踪透明度授权 static Future get requestIDFA async { if (Platform.isIOS) { final bool result = await _methodChannel.invokeMethod('requestIDFA'); return result; } return true; } /// 初始化广告 /// [appId] 应用媒体ID static Future initAd(String appId) async { final bool result = await _methodChannel.invokeMethod( 'initAd', {'appId': appId}, ); print("🎉🎉🎉 UnionAd ==> 初始化完成"); return result; } /// 设置个性化广告 /// 0:代表开启个性化广告推荐,1:代表关闭个性化广告推荐 static Future setPersonalizedState(int state) async { final bool result = await _methodChannel.invokeMethod( 'setPersonalizedState', {'state': state}, ); return result; } /// 展示开屏广告 /// [posId] 广告位 id /// [logo] 如果传值则展示底部logo,不传不展示,则全屏展示 /// [fetchDelay] 拉取广告的超时时间,默认值 3 秒,取值范围[1.5~5]秒 static Future showSplashAd(String posId, {String? logo, double fetchDelay = 3}) async { final bool result = await _methodChannel.invokeMethod( 'showSplashAd', { 'posId': posId, 'logo': logo, 'fetchDelay': fetchDelay, }, ); return result; } /// 展示激励视频广告 /// [posId] 广告位 id /// [playMuted] 是否静音播放 /// [customData] 设置服务端验证的自定义信息 /// [userId] 设置服务端验证的用户信息 static Future showRewardVideoAd( String posId, { bool playMuted = false, String? customData, String? userId, }) async { final bool result = await _methodChannel.invokeMethod( 'showRewardVideoAd', { 'posId': posId, 'playMuted': playMuted, 'customData': customData, 'userId': userId, }, ); return result; } ///事件回调 ///@params onData 事件回调 static Future onEventListener( OnAdEventListener onAdEventListener) async { _eventChannel.receiveBroadcastStream().listen((data) { hanleAdEvent(data, onAdEventListener); }); } Future getPlatformVersion() { return UnionAdSsgfPlatform.instance.getPlatformVersion(); } }