删除无用代码

This commit is contained in:
Jin857 2024-11-26 11:37:48 +08:00
parent 9a4ec3a4d0
commit 61f484c80c
6 changed files with 20 additions and 342 deletions

View File

@ -1,8 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.union_ad_ssgf_example">
<!-- android:name="${applicationName}" -->
<application
android:label="SsgfUnionAd"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"

View File

@ -11,7 +11,7 @@ class AdsConfig {
static String iosInterstitialId = "7046066294830767";
/// 广id
static String androidInterstitialFullScreenVideoId = "3012521499614895";
static String androidInterstitialFullScreenVideoId = "6152080663982456";
static String iosInterstitialFullScreenVideoId = "3092322459911886";
/// 广id

View File

@ -15,7 +15,7 @@ class HomePage extends StatefulWidget {
class _HomePageState extends State<HomePage> {
String adVersion = '';
StreamSubscription? _adViewStream;
@override
void dispose() {
_adViewStream?.cancel();
@ -153,24 +153,6 @@ class _HomePageState extends State<HomePage> {
),
],
),
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<HomePage> {
),
],
),
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<HomePage> {
}
/// 广
Future<void> showInterstitialAd() async {}
Future<void> showInterstitialAd() async {
await FlutterUnionAd.loadUnifiedInterstitialAD(
//android广告id
androidId: AdsConfig.androidInterstitialRewardVideoId,
//ios广告id
iosId: AdsConfig.iosRewardVideoId,
// false
downloadConfirm: false,
//
isBidding: false,
isFullScreen: false,
);
}
///
Future<void> version() async {
@ -225,7 +211,7 @@ Future<void> showSplashAd(context) async {
MaterialPageRoute(
builder: (_) {
return SplashPage(
isBidding: true,
isBidding: false,
androidId: AdsConfig.androidSplashId,
iosId: AdsConfig.iosSplashId,
);
@ -250,8 +236,8 @@ Future<void> showRewardVideoAd() async {
// 使
customData: "",
// false
downloadConfirm: true,
downloadConfirm: false,
//
isBidding: true,
isBidding: false,
);
}

View File

@ -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)
}
}

View File

@ -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("视频播放结束")
}
}

View File

@ -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)")
}
}