union_ad_ssgf/lib/union_ad_ssgf.dart
2024-10-16 10:52:08 +08:00

76 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<bool> get requestIDFA async {
if (Platform.isIOS) {
final bool result = await _methodChannel.invokeMethod('requestIDFA');
return result;
}
return true;
}
/// 初始化广告
/// [appId] 应用媒体ID
static Future<bool> initAd(String appId) async {
final bool result = await _methodChannel.invokeMethod(
'initAd',
{'appId': appId},
);
print("🎉🎉🎉 UnionAd ==> 初始化完成");
return result;
}
/// 设置个性化广告
/// 0代表开启个性化广告推荐1代表关闭个性化广告推荐
static Future<bool> 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<bool> showSplashAd(String posId,
{String? logo, double fetchDelay = 3}) async {
final bool result = await _methodChannel.invokeMethod(
'showSplashAd',
{
'posId': posId,
'logo': logo,
'fetchDelay': fetchDelay,
},
);
return result;
}
///事件回调
///@params onData 事件回调
static Future<void> onEventListener(OnAdEventListener onAdEventListener) async {
_eventChannel.receiveBroadcastStream().listen((data) {
hanleAdEvent(data, onAdEventListener);
});
}
Future<String?> getPlatformVersion() {
return UnionAdSsgfPlatform.instance.getPlatformVersion();
}
}