diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 6d40936..a94f563 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,8 +1,8 @@ + { String adVersion = ''; StreamSubscription? _adViewStream; - + @override void dispose() { _adViewStream?.cancel(); @@ -153,24 +153,6 @@ class _HomePageState extends State { ), ], ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ElevatedButton( - child: const Text('插屏广告'), - onPressed: () { - showInterstitialAd(); - }, - ), - const SizedBox(height: 20), - ElevatedButton( - child: const Text('插全屏广告'), - onPressed: () { - showInterstitialAd(); - }, - ), - ], - ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -189,15 +171,6 @@ class _HomePageState extends State { ), ], ), - const SizedBox(height: 20), - ElevatedButton( - child: const Text('信息流'), - onPressed: () {}, - ), - const SizedBox(height: 20), - const Center(child: Text('👇🏻 Banner 广告 👇🏻')), - const SizedBox(height: 10), - const SizedBox(height: 10), ], ), ), @@ -206,7 +179,20 @@ class _HomePageState extends State { } /// 展示插屏广告 - Future showInterstitialAd() async {} + Future showInterstitialAd() async { + await FlutterUnionAd.loadUnifiedInterstitialAD( + //android广告id + androidId: AdsConfig.androidInterstitialRewardVideoId, + //ios广告id + iosId: AdsConfig.iosRewardVideoId, + + //下载二次确认弹窗 默认false + downloadConfirm: false, + //开启竞价 + isBidding: false, + isFullScreen: false, + ); + } /// 当前版本 Future version() async { @@ -225,7 +211,7 @@ Future showSplashAd(context) async { MaterialPageRoute( builder: (_) { return SplashPage( - isBidding: true, + isBidding: false, androidId: AdsConfig.androidSplashId, iosId: AdsConfig.iosSplashId, ); @@ -250,8 +236,8 @@ Future showRewardVideoAd() async { //扩展参数 服务器回调使用 customData: "", //下载二次确认弹窗 默认false - downloadConfirm: true, + downloadConfirm: false, //开启竞价 - isBidding: true, + isBidding: false, ); } diff --git a/ios/Classes/Page/FAQBaseAdPage.swift b/ios/Classes/Page/FAQBaseAdPage.swift deleted file mode 100644 index ac6ccc7..0000000 --- a/ios/Classes/Page/FAQBaseAdPage.swift +++ /dev/null @@ -1,72 +0,0 @@ - -import Flutter -import UIKit - -// 基础 - 广告页面 -class FAQBaseAdPage: NSObject { - let kPosId = "posId" - - var posId: String! - var eventSink: FlutterEventSink? - var mainWin: UIWindow? - var rootController: UIViewController? - var width: CGFloat = 0 - var height: CGFloat = 0 - - // 添加广告事件 - func addAdEvent(_ event: FAQAdEvent) { - if let eventSink = self.eventSink { - eventSink(event.toMap()) - } - } - - // 显示广告 - func showAd(call: FlutterMethodCall, eventSink: @escaping FlutterEventSink) { - guard let arguments = call.arguments as? [String: Any], - let posId = arguments[kPosId] as? String - else { - return - } - - self.posId = posId - self.eventSink = eventSink - - // 获取主 window - self.mainWin = UIApplication.shared.keyWindow - - // 获取 rootViewController - self.rootController = self.mainWin?.rootViewController - - // 获取宽高 - let size = UIScreen.main.bounds.size - self.width = size.width - self.height = size.height - - loadAd(call: call) - } - - // 加载广告 - func loadAd(call: FlutterMethodCall) { - print(#function) // 使用 Swift 的 print 代替 NSLog - } - - // 发送广告事件 - func sendEvent(_ event: FAQAdEvent) { - if let eventSink = self.eventSink { - eventSink(event.toMap()) - } - } - - // 发送广告事件 - func sendEventAction(_ action: String) { - let event = FAQAdEvent(adId: self.posId, action: action) - sendEvent(event) - } - - // 发送广告错误事件 - func sendErrorEvent(errCode: Int, errMsg: String) { - let event = FAQAdErrorEvent( - adId: self.posId, errCode: NSNumber(value: errCode), errMsg: errMsg) - sendEvent(event) - } -} diff --git a/ios/Classes/Page/FAQRewardVideoPage.swift b/ios/Classes/Page/FAQRewardVideoPage.swift deleted file mode 100644 index 83031bb..0000000 --- a/ios/Classes/Page/FAQRewardVideoPage.swift +++ /dev/null @@ -1,106 +0,0 @@ -import Flutter -import UIKit - -// 激励视频页面 -class FAQRewardVideoPage: FAQBaseAdPage, GDTRewardedVideoAdDelegate { - // 激励视频广告对象 - var rvad: GDTRewardVideoAd? - // 服务端验证的自定义信息 - var customData: String? - // 服务端验证的用户信息 - var userId: String? - - // 加载广告 - override func loadAd(call: FlutterMethodCall) { - guard let arguments = call.arguments as? [String: Any], - let customData = arguments["customData"] as? String, - let userId = arguments["userId"] as? String, - let playMuted = arguments["playMuted"] as? Bool - else { - return - } - - self.customData = customData - self.userId = userId - - // 初始化激励视频广告 - self.rvad = GDTRewardVideoAd(placementId: self.posId) - self.rvad?.delegate = self - self.rvad?.videoMuted = playMuted - - // 如果设置了服务端验证,可以设置 serverSideVerificationOptions 属性 - let ssv = GDTServerSideVerificationOptions() - ssv.userIdentifier = self.userId - ssv.customRewardString = self.customData - self.rvad?.serverSideVerificationOptions = ssv - self.rvad?.load() - } - - // MARK: - GDTRewardVideoAdDelegate - - func gdt_rewardVideoAdDidLoad(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - if let controller = UIApplication.shared.keyWindow?.rootViewController { - self.rvad?.show(fromRootViewController: controller) - // 发送广告事件 - self.sendEventAction(onAdLoaded) - } - } - - func gdt_rewardVideoAdVideoDidLoad(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - } - - func gdt_rewardVideoAdWillVisible(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - // 发送广告事件 - self.sendEventAction(onAdPresent) - } - - func gdt_rewardVideoAdDidExposed(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - print("广告已曝光") - // 发送广告事件 - self.sendEventAction(onAdExposure) - } - - func gdt_rewardVideoAdDidClose(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - print("广告已关闭") - // 发送广告事件 - self.sendEventAction(onAdClosed) - } - - func gdt_rewardVideoAdDidClicked(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - print("广告已点击") - // 发送广告事件 - self.sendEventAction(onAdClicked) - } - - func gdt_rewardVideoAd(_ rewardedVideoAd: GDTRewardVideoAd, didFailWithError error: Error) { - print(#function) - print("ERROR: \(error.localizedDescription)") - // 发送广告错误事件 - self.sendErrorEvent(errCode: (error as NSError).code, errMsg: error.localizedDescription) - } - - func gdt_rewardVideoAdDidRewardEffective( - _ rewardedVideoAd: GDTRewardVideoAd, info: [AnyHashable: Any] - ) { - print(#function) - if let transId = info["GDT_TRANS_ID"] as? String { - print("播放达到激励条件 transid: \(transId)") - // 发送激励事件 - let event = FAQAdRewardEvent( - adId: self.posId, transId: transId, customData: self.customData!, - userId: self.userId!) - self.sendEvent(event) - } - } - - func gdt_rewardVideoAdDidPlayFinish(_ rewardedVideoAd: GDTRewardVideoAd) { - print(#function) - print("视频播放结束") - } -} diff --git a/ios/Classes/Page/FAQSplashPage.swift b/ios/Classes/Page/FAQSplashPage.swift deleted file mode 100644 index ba11309..0000000 --- a/ios/Classes/Page/FAQSplashPage.swift +++ /dev/null @@ -1,130 +0,0 @@ -import UIKit -import Flutter - -class FAQSplashPage: FAQBaseAdPage, GDTSplashAdDelegate { - var splashAd: GDTSplashAd! - var fullScreenAd: Bool = false - var bottomView: UIView? - - // 加载广告 - override func loadAd(call: FlutterMethodCall) { - // 获取 logo 和 fetchDelay - guard let arguments = call.arguments as? [String: Any], - let logo = arguments["logo"] as? String, - let fetchDelay = arguments["fetchDelay"] as? CGFloat - else { - - } - - print("---->>> logo: \(logo)") - // logo 判断为空,则全屏展示 - self.fullScreenAd = logo.isEmpty - - // 初始化开屏广告 - self.splashAd = GDTSplashAd(placementId: self.posId) - // 确保 FAQSplashPage 遵循适当的协议 - self.splashAd.delegate = self - // 设置超时时长 - self.splashAd.fetchDelay = fetchDelay - - // 加载全屏广告 - if self.fullScreenAd { - self.splashAd.loadFullScreenAd() - } else { - // 加载半屏广告 - self.splashAd.load() - // 设置底部 logo - self.bottomView = nil - let size = UIScreen.main.bounds.size - let width = size.width - // 这里按照 15% 进行 logo 的展示 - let height: CGFloat = 112.5 - self.bottomView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: height)) - self.bottomView?.backgroundColor = .white - if let logoImage = UIImage(named: logo) { - let logoView = UIImageView(image: logoImage) - logoView.frame = CGRect(x: 0, y: 0, width: width, height: height) - logoView.contentMode = .center - logoView.center = self.bottomView!.center - self.bottomView?.addSubview(logoView) - } - } - } - - // MARK: - GDTSplashAdDelegate - func splashAdDidLoad(_ splashAd: GDTSplashAd) { - print("splashAdDidLoad") - if let mainWindow = UIApplication.shared.keyWindow { - // 加载全屏广告 - if self.fullScreenAd { - self.splashAd.showFullScreenAd(in: mainWindow, withLogoImage: nil, skip: nil) - } else { - // 加载半屏广告 - self.splashAd.show(in: mainWindow, withBottomView: self.bottomView, skip: nil) - } - // 发送广告事件 - sendEventAction("onAdLoaded") - } - } - - func splashAdSuccessPresentScreen(_ splashAd: GDTSplashAd) { - print(#function) - // 发送广告事件 - sendEventAction("onAdPresent") - } - - func splashAdFail(toPresent splashAd: GDTSplashAd, withError error: Error) { - print("\( #function) \(error.localizedDescription)") - // 发送广告错误事件 - sendErrorEvent(error._code, withErrMsg: error.localizedDescription) - } - - func splashAdExposured(_ splashAd: GDTSplashAd) { - print(#function) - // 发送广告事件 - sendEventAction("onAdExposure") - } - - func splashAdClicked(_ splashAd: GDTSplashAd) { - print(#function) - // 发送广告事件 - sendEventAction("onAdClicked") - } - - func splashAdApplicationWillEnterBackground(_ splashAd: GDTSplashAd) { - print(#function) - } - - func splashAdWillClosed(_ splashAd: GDTSplashAd) { - print(#function) - } - - func splashAdClosed(_ splashAd: GDTSplashAd) { - print(#function) - self.splashAd = nil - // 发送广告事件 - sendEventAction("onAdClosed") - } - - func splashAdWillPresentFullScreenModal(_ splashAd: GDTSplashAd) { - print(#function) - } - - func splashAdDidPresentFullScreenModal(_ splashAd: GDTSplashAd) { - print(#function) - } - - func splashAdWillDismissFullScreenModal(_ splashAd: GDTSplashAd) { - print(#function) - } - - func splashAdDidDismissFullScreenModal(_ splashAd: GDTSplashAd) { - print(#function) - } - - // 发送错误事件的示例方法 - private func sendErrorEvent(_ code: Int, withErrMsg msg: String) { - // 实现发送错误事件的逻辑 - print("Error sent: \(code); message: \(msg)") - } -}