ios 代码添加

This commit is contained in:
Jin857 2024-11-26 11:14:20 +08:00
parent eea39e2ada
commit 9a4ec3a4d0
35 changed files with 1489 additions and 321 deletions

View File

@ -47,6 +47,7 @@ internal class SplashAdView(
}
private fun loadSplashAd() {
LogUtil.e("codeId: $codeId , fetchDelay: $fetchDelay")
splashAD = SplashAD(activity, codeId, this, fetchDelay)
mContainer?.removeAllViews()
splashAD?.fetchAdOnly()
@ -64,7 +65,7 @@ internal class SplashAdView(
channel?.invokeMethod("onClose", "")
}
//广告加载失败error 对象包含了错误码和错误信息错误码的详细内容可以参考文档第5章
// 广告加载失败error 对象包含了错误码和错误信息错误码的详细内容可以参考文档第5章
override fun onNoAD(p0: AdError?) {
LogUtil.e("开屏广告加载失败 ${p0?.errorCode} ${p0?.errorMsg}")
var map: MutableMap<String, Any?> = mutableMapOf("code" to p0?.errorCode, "message" to p0?.errorMsg)

View File

@ -24,7 +24,6 @@ if (flutterVersionName == null) {
android {
namespace = "com.example.union_ad_ssgf_example"
// namespace = "com.zero.flutter_qq_ads_example"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
@ -34,7 +33,7 @@ android {
}
defaultConfig {
applicationId = "com.example.union_ad_ssgf_example"
applicationId = "com.example.union_ad_ssgf_example"
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutterVersionCode.toInteger()

View File

@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.union_ad_ssgf_example">
<application
android:label="SsgfUnionAd"
android:name="${applicationName}"

View File

@ -27,9 +27,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
GDTMobSDK: 71e264496ba2ade7d9ce528f4eba1a5424a86654
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
union_ad_ssgf: 3f80727f998984d321ad5247ed5aefb073e9488c
PODFILE CHECKSUM: 0bf49b915f0287a57df9b036ff94509feb1aeb65
COCOAPODS: 1.15.2
COCOAPODS: 1.16.2

View File

@ -3,6 +3,7 @@ class AdsConfig {
static String androidAppId = "1208618114";
static String iosAppId = "1208619454";
// static String androidSplashId = "5172884622215995";
static String androidSplashId = "1122289510576542";
static String iosSplashId = "7142786521331351";

View File

@ -225,7 +225,7 @@ Future<void> showSplashAd(context) async {
MaterialPageRoute(
builder: (_) {
return SplashPage(
isBidding: false,
isBidding: true,
androidId: AdsConfig.androidSplashId,
iosId: AdsConfig.iosSplashId,
);

View File

@ -37,7 +37,7 @@ class _MyAppState extends State<MyApp> {
androidId: AdsConfig.androidAppId,
iosId: AdsConfig.iosAppId,
debug: true, // log
personalized: FlutterTencentadPersonalized.show, // 广
personalized: FlutterTencentadPersonalized.close, // 广
channelId: FlutterTencentadChannel.tencent, //id
);
debugPrint("广告SDK 初始化${result ? '成功' : '失败'}");

View File

@ -26,14 +26,13 @@ class _SplashPageState extends State<SplashPage> {
Widget build(BuildContext context) {
return Scaffold(
body: Container(
color: Colors.red,
child: FlutterUnionAd.splashAdView(
// android广告id
androidId: widget.androidId,
// ios广告id
iosId: widget.iosId,
// 广广[1500, 5000]ms
fetchDelay: 3000,
fetchDelay: 5000,
// false
downloadConfirm: true,
//

View File

@ -1,32 +0,0 @@
//
// FAQAdErrorEvent.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import Foundation
// 广
class FAQAdErrorEvent: FAQAdEvent {
//
var errCode: NSNumber
//
var errMsg: String
// 广
init(adId: String, errCode: NSNumber, errMsg: String) {
self.errCode = errCode
self.errMsg = errMsg
super.init(adId: adId, action: "onAdError") // onAdError
}
//
override func toMap() -> [String: Any] {
var errData = super.toMap() //
errData["errCode"] = errCode //
errData["errMsg"] = errMsg //
return errData //
}
}

View File

@ -1,27 +0,0 @@
//
// FAQAdEvent.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import Foundation
//
class FAQAdEvent {
// 广 id
var adId: String
//
var action: String
// - 广
init(adId: String, action: String) {
self.adId = adId
self.action = action
}
// Map
func toMap() -> [String: Any] {
return ["adId": adId, "action": action]
}
}

View File

@ -1,43 +0,0 @@
//
// FAQAdEventAction.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import Foundation
//广
// 广
let onAdError = "onAdError"
// 广
let onAdLoaded = "onAdLoaded"
// 广
let onAdPresent = "onAdPresent"
// 广
let onAdExposure = "onAdExposure"
// 广
let onAdClosed = "onAdClosed"
// 广
let onAdClicked = "onAdClicked"
// 广
let onAdSkip = "onAdSkip"
// 广
let onAdComplete = "onAdComplete"
// 广
let onAdReward = "onAdReward"
// 广
class FAQAdEventAction: NSObject {
// 广
}

View File

@ -1,36 +0,0 @@
//
// FAQAdRewardEvent.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import Foundation
// 广
class FAQAdRewardEvent: FAQAdEvent {
// id
var transId: String
//
var customData: String
//
var userId: String
// 广
init(adId: String, transId: String, customData: String, userId: String) {
self.transId = transId
self.customData = customData
self.userId = userId
super.init(adId: adId, action: onAdReward) // onAdReward
}
//
override func toMap() -> [String: Any] {
var errData = super.toMap() //
errData["transId"] = transId // transId
errData["customData"] = customData // customData
errData["userId"] = userId // userId
return errData //
}
}

View File

@ -1,9 +1,3 @@
//
// FAQBaseAdPage.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import Flutter
import UIKit

View File

@ -1,12 +1,5 @@
//
// FAQRewardVideoPage.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import UIKit
import Flutter
import UIKit
//
class FAQRewardVideoPage: FAQBaseAdPage, GDTRewardedVideoAdDelegate {
@ -22,13 +15,14 @@ class FAQRewardVideoPage: FAQBaseAdPage, GDTRewardedVideoAdDelegate {
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 {
let playMuted = arguments["playMuted"] as? Bool
else {
return
}
self.customData = customData
self.userId = userId
// 广
self.rvad = GDTRewardVideoAd(placementId: self.posId)
self.rvad?.delegate = self
@ -91,12 +85,16 @@ class FAQRewardVideoPage: FAQBaseAdPage, GDTRewardedVideoAdDelegate {
self.sendErrorEvent(errCode: (error as NSError).code, errMsg: error.localizedDescription)
}
func gdt_rewardVideoAdDidRewardEffective(_ rewardedVideoAd: GDTRewardVideoAd, info: [AnyHashable: Any]) {
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!)
let event = FAQAdRewardEvent(
adId: self.posId, transId: transId, customData: self.customData!,
userId: self.userId!)
self.sendEvent(event)
}
}

View File

@ -1,10 +1,3 @@
//
// FAQSplashPage.swift
// Pods
//
// Created by Jin on 10/23/24.
//
import UIKit
import Flutter

View File

@ -1,5 +0,0 @@
#import <GDTMobSDK/GDTNativeExpressAdView.h>
#import <GDTMobSDK/GDTNativeExpressAd.h>
#import <GDTMobSDK/GDTRewardVideoAd.h>
#import <GDTMobSDK/GDTSplashAd.h>
#import <GDTMobSDK/GDTSDKConfig.h>

View File

@ -0,0 +1,4 @@
#import <Flutter/Flutter.h>
@interface UnionAdSsgfPlugin : NSObject<FlutterPlugin>
@end

View File

@ -0,0 +1,66 @@
#import "UnionAdSsgfPlugin.h"
#import "GDTSDKConfig.h"
#import "UnionAdSsgfEvent.h"
#import "RewardAd.h"
#import "TLogUtil.h"
#import "InsertAd.h"
#import "SplashAd.h"
#import "BannerAd.h"
#import "NativeAd.h"
@implementation UnionAdSsgfPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
methodChannelWithName:@"flutter_union_ad"
binaryMessenger:[registrar messenger]];
UnionAdSsgfPlugin* instance = [[UnionAdSsgfPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
//event
[[UnionAdSsgfEvent sharedInstance] initEvent:registrar];
//splash
[registrar registerViewFactory:[[SplashAdFactory alloc] initWithMessenger:registrar.messenger] withId:@"com.example.union_ad_ssgf/SplashAdView"];
//banner
[registrar registerViewFactory:[[BannerAdFactory alloc] initWithMessenger:registrar.messenger] withId:@"com.example.union_ad_ssgf/BannerAdView"];
//native
[registrar registerViewFactory:[[NaitveAdFactory alloc] initWithMessenger:registrar.messenger] withId:@"com.example.union_ad_ssgf/NativeExpressAdView"];
}
- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"register" isEqualToString:call.method]) {
NSString *appId = call.arguments[@"iosId"];
BOOL debug = [call.arguments[@"debug"] boolValue];
BOOL isInit = [GDTSDKConfig initWithAppId:appId];
NSInteger personalized = [call.arguments[@"personalized"] intValue];
NSInteger channelId = [call.arguments[@"channelId"] intValue];
//
[GDTSDKConfig setPersonalizedState:personalized];
//id
[GDTSDKConfig setChannel:channelId];
[[TLogUtil sharedInstance] debug:debug];
result([NSNumber numberWithBool:isInit]);
}else if([@"getSDKVersion" isEqualToString:call.method]){
NSString *version = [GDTSDKConfig sdkVersion];
result(version);
//广
}else if([@"loadRewardVideoAd" isEqualToString:call.method]){
[[RewardAd sharedInstance] initAd:call.arguments];
result(@YES);
//广
}else if([@"showRewardVideoAd" isEqualToString:call.method]){
[[RewardAd sharedInstance] showAd:call.arguments];
result(@YES);
//广
}else if([@"loadInterstitialAD" isEqualToString:call.method]){
[[InsertAd sharedInstance] initAd:call.arguments];
result(@YES);
////广
}else if([@"showInterstitialAD" isEqualToString:call.method]){
[[InsertAd sharedInstance] showAd:call.arguments];
result(@YES);
} else {
result(FlutterMethodNotImplemented);
}
}
@end

View File

@ -1,142 +0,0 @@
import Flutter
import AppTrackingTransparency
import AdSupport
public class UnionAdSsgfPlugin: NSObject, FlutterPlugin ,FlutterStreamHandler{
static var methodName = "union_ad_ssgf_method"
static var eventName = "union_ad_ssgf_event"
var splashAd: FAQSplashPage?
var rewardAd: FAQRewardVideoPage?
var sink:FlutterEventSink?
public static func register(with registrar: FlutterPluginRegistrar) {
let methodChannel = FlutterMethodChannel(name: methodName, binaryMessenger: registrar.messenger());
let eventChannel = FlutterEventChannel(name: eventName, binaryMessenger: registrar.messenger());
let instance = UnionAdSsgfPlugin();
registrar.addMethodCallDelegate(instance, channel: methodChannel);
eventChannel.setStreamHandler(instance);
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "getPlatformVersion":
getPlatformVersion(call: call, result: result)
case "requestIDFA":
requestIDFA(call: call, result: result)
case "initAd": //
initAd(call:call, result: result);
case "setPersonalizedState": // 广
setPersonalizedState(call:call, result: result);
case "showSplashAd": // 广
showSplashAd(call:call, result: result);
case "showRewardVideoAd": // 广
showRewardVideoAd(call:call, result: result);
default:
result(FlutterMethodNotImplemented)
}
}
//
public func getPlatformVersion(call: FlutterMethodCall, result: @escaping FlutterResult) {
result("iOS " + UIDevice.current.systemVersion)
}
// 广
public func initAd(call: FlutterMethodCall, result: @escaping FlutterResult) {
if let arguments = call.arguments as? [String: Any],
let appId = arguments["appId"] as? String {
print("App ID: \(appId)")
//
let initSuccess = GDTSDKConfig.initWithAppId(appId)
print("初始化插件 initSuccess: \(initSuccess)")
result(NSNumber(value: initSuccess))
GDTSDKConfig.start {success, error in
//
result(true)
if success {
result(NSNumber(value: true))
} else {
result(NSNumber(value: false))
if let error = error {
print("FlutterQqAdsPlugin initAd error: \(error.localizedDescription)")
}
}
}
} else {
print("appId not found or invalid type.")
result(NSNumber(value: false)) // appId
}
}
//
public func requestIDFA(call: FlutterMethodCall, result: @escaping FlutterResult) {
if #available(iOS 14, *) {
ATTrackingManager.requestTrackingAuthorization { status in
let requestResult = (status == .authorized)
print("requestIDFA: \(requestResult ? "YES" : "NO")")
result(requestResult)
}
} else {
result(true)
}
}
// 广
public func setPersonalizedState(call: FlutterMethodCall, result: @escaping FlutterResult) {
if let arguments = call.arguments as? [String: Any],
let state = arguments["state"] as? Int {
print("Set State : \(state)")
GDTSDKConfig.setPersonalizedState(state)
result(NSNumber(value: true))
} else {
print("appId not found or invalid type.")
result(NSNumber(value: false)) // appId
}
}
// 广
public func showSplashAd(call: FlutterMethodCall, result: FlutterResult) {
// FAQSplashPage
self.splashAd = FAQSplashPage()
if(self.sink != nil){
print("--------------->>>>> showSplashAd");
self.splashAd?.showAd(call: call, eventSink: self.sink!)
result(true)
}else{
result(NSNumber(value: false))
}
}
// 广
public func showRewardVideoAd(call: FlutterMethodCall, result: FlutterResult) {
// FAQRewardVideoPage
self.rewardAd = FAQRewardVideoPage();
if(self.sink != nil){
self.rewardAd?.showAd(call: call, eventSink: self.sink!)
result(NSNumber(value: true))
}else{
result(NSNumber(value: false))
}
}
//
public func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
self.sink = events
return nil
}
//
public func onCancel(withArguments arguments: Any?) -> FlutterError? {
self.sink = nil;
return nil;
}
//
private func addEvent(_ event: NSObject) {
self.sink?(event)
}
}

View File

@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface BannerAdFactory : NSObject<FlutterPlatformViewFactory>
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messager;
@end
@interface BannerAd : NSObject<FlutterPlatformView>
- (instancetype)initWithWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,187 @@
#import "BannerAd.h"
#import "GDTUnifiedBannerView.h"
#import "TLogUtil.h"
#import "TUIViewController+getCurrentVC.h"
#pragma mark - BannerAdFactory
@implementation BannerAdFactory{
NSObject<FlutterBinaryMessenger>*_messenger;
}
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messager{
self = [super init];
if (self) {
_messenger = messager;
}
return self;
}
-(NSObject<FlutterMessageCodec> *)createArgsCodec{
return [FlutterStandardMessageCodec sharedInstance];
}
-(NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args{
BannerAd * bannerAd = [[BannerAd alloc] initWithWithFrame:frame viewIdentifier:viewId arguments:args binaryMessenger:_messenger];
return bannerAd;
}
@end
@interface BannerAd()<GDTUnifiedBannerViewDelegate>
@property (nonatomic, strong) GDTUnifiedBannerView *banner;
@property(nonatomic,strong) UIView *container;
@property(nonatomic,assign) CGRect frame;
@property(nonatomic,assign) NSInteger viewId;
@property(nonatomic,strong) FlutterMethodChannel *channel;
@property(nonatomic,strong) NSString *codeId;
@property(nonatomic,assign) NSInteger viewWidth;
@property(nonatomic,assign) NSInteger viewHeight;
@property(nonatomic,assign) BOOL isBidding;
@end
@implementation BannerAd
- (instancetype)initWithWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args binaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger{
if ([super init]) {
NSDictionary *dic = args;
_frame = frame;
_viewId = viewId;
_codeId = dic[@"iosId"];
_viewWidth =[dic[@"viewWidth"] intValue];
_viewHeight =[dic[@"viewHeight"] intValue];
self.isBidding =[dic[@"isBidding"] boolValue];
NSString* channelName = [NSString stringWithFormat:@"com.example.union_ad_ssgf/BannerAdView_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
[self.channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
//
if ([@"biddingSucceeded" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_W_E_COST_PRICE:@([call.arguments[@"expectCostPrice"] intValue]),
GDT_M_W_H_LOSS_PRICE:@([call.arguments[@"highestLossPrice"] intValue])
};
[self->_banner sendWinNotificationWithInfo:dictionary];
NSDictionary *dictionary2 = @{@"width": @(self.banner.frame.size.width),@"height":@(self.banner.frame.size.height)};
[_channel invokeMethod:@"onShow" arguments:dictionary2 result:nil];
//
} else if([@"biddingFail" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_L_WIN_PRICE:@([call.arguments[@"winPrice"] intValue]),
GDT_M_L_LOSS_REASON:@([call.arguments[@"lossReason"] intValue]),
GDT_M_ADNID: call.arguments[@"adnId"]};
[self.banner sendWinNotificationWithInfo:dictionary];
}
}];
[self loadBannerAd];
}
return self;
}
- (UIView*)view{
return self.container;
}
-(void)loadBannerAd{
[_container removeFromSuperview];
CGRect rect = {CGPointZero, CGSizeMake(_viewWidth, _viewHeight)};
if(self.banner == nil){
self.banner = [[GDTUnifiedBannerView alloc] initWithFrame:rect placementId:_codeId viewController:[UIViewController jsd_getCurrentViewController]];
self.banner.delegate = self;
self.banner.autoSwitchInterval = 30;
}
self.container = self.banner;
[self.banner loadAdAndShow];
}
/**
* 广
* 广
*/
- (void)unifiedBannerViewDidLoad:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"Banner广告数据请求成功"];
// [[TLogUtil sharedInstance] print:self.banner.eCPMLevel];
// [[TLogUtil sharedInstance] print:@(self.banner.eCPM)];
//
if(self.isBidding){
NSDictionary *dictionary = @{@"ecpmLevel":self.banner.eCPMLevel == nil ? @"" : self.banner.eCPMLevel,@"ecpm":@(self.banner.eCPM)};
[self.channel invokeMethod:@"onECPM" arguments:dictionary result:nil];
}else{
// [self.container addSubview:self.banner];
NSDictionary *dictionary = @{@"width": @(unifiedBannerView.frame.size.width),@"height":@(unifiedBannerView.frame.size.height)};
[self.channel invokeMethod:@"onShow" arguments:dictionary result:nil];
}
}
/**
* 广
* 广
*/
- (void)unifiedBannerViewFailedToLoad:(GDTUnifiedBannerView *)unifiedBannerView error:(NSError *)error{
[[TLogUtil sharedInstance] print:@"请求广告条数据失败后调用"];
NSDictionary *dictionary = @{@"code":@(-1),@"message":error.description};
[_channel invokeMethod:@"onFail" arguments:dictionary result:nil];
}
/**
* banner2.0
*/
- (void)unifiedBannerViewWillExpose:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"banner2.0曝光回调"];
[_channel invokeMethod:@"onExpose" arguments:nil result:nil];
}
/**
* banner2.0
*/
- (void)unifiedBannerViewClicked:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"banner2.0点击回调"];
[_channel invokeMethod:@"onClick" arguments:nil result:nil];
}
/**
* banner2.0广广
*/
- (void)unifiedBannerViewWillPresentFullScreenModal:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"banner2.0广告点击以后即将弹出全屏广告页"];
}
/**
* banner2.0广广
*/
- (void)unifiedBannerViewDidPresentFullScreenModal:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"banner2.0广告点击以后弹出全屏广告页完毕"];
}
/**
* 广
*/
- (void)unifiedBannerViewWillDismissFullScreenModal:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"全屏广告页即将被关闭"];
}
/**
* 广
*/
- (void)unifiedBannerViewDidDismissFullScreenModal:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"全屏广告页已经被关闭"];
}
/**
* 广
*/
- (void)unifiedBannerViewWillLeaveApplication:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"当点击应用下载或者广告调用系统程序打开"];
}
/**
* banner2.0
* banner广 - 广广
* unifiedBannerViewviewnil
*/
- (void)unifiedBannerViewWillClose:(GDTUnifiedBannerView *)unifiedBannerView{
[[TLogUtil sharedInstance] print:@"banner2.0被用户关闭时调用"];
[_channel invokeMethod:@"onClose" arguments:nil result:nil];
}
@end

View File

@ -0,0 +1,12 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface UnionAdSsgfEvent : NSObject
+ (instancetype)sharedInstance;
- (void)initEvent:(NSObject<FlutterPluginRegistrar>*)registrar;
- (void)sentEvent:(NSDictionary*)arguments;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,41 @@
#import "UnionAdSsgfEvent.h"
#import <Flutter/Flutter.h>
@interface UnionAdSsgfEvent () <FlutterStreamHandler>
@property(nonatomic, strong) FlutterEventSink eventSink;
@end
@implementation UnionAdSsgfEvent
+ (instancetype)sharedInstance {
static UnionAdSsgfEvent *myInstance = nil;
if (myInstance == nil) {
myInstance = [[UnionAdSsgfEvent alloc] init];
}
return myInstance;
}
- (void)initEvent:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterEventChannel *eventChannel = [FlutterEventChannel
eventChannelWithName:@"com.example.union_ad_ssgf/adevent"
binaryMessenger:[registrar messenger]];
[eventChannel setStreamHandler:self];
}
- (void)sentEvent:(NSDictionary *)arguments {
self.eventSink(arguments);
}
#pragma mark - FlutterStreamHandler
- (FlutterError *_Nullable)onCancelWithArguments:(id _Nullable)arguments {
self.eventSink = nil;
return nil;
}
- (FlutterError *_Nullable)onListenWithArguments:(id _Nullable)arguments
eventSink:
(nonnull FlutterEventSink)events {
self.eventSink = events;
return nil;
}
@end

View File

@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface InsertAd : NSObject
+ (instancetype)sharedInstance;
- (void)initAd:(NSDictionary *)arguments;
- (void)showAd:(NSDictionary *)arguments;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,263 @@
#import "InsertAd.h"
#import "GDTUnifiedInterstitialAd.h"
#import "TLogUtil.h"
#import "TUIViewController+getCurrentVC.h"
#import "UnionAdSsgfEvent.h"
@interface InsertAd()<GDTUnifiedInterstitialAdDelegate>
@property(nonatomic,strong) GDTUnifiedInterstitialAd *interstitialAd;
@property(nonatomic,strong) NSString *codeId;
@property(nonatomic,assign) BOOL isFullScreen;
@property(nonatomic,assign) BOOL isBidding;
@property(nonatomic,strong) UIViewController *currentController;
@end
@implementation InsertAd
+ (instancetype)sharedInstance{
static InsertAd *myInstance = nil;
if(myInstance == nil){
myInstance = [[InsertAd alloc]init];
}
return myInstance;
}
//广
-(void)initAd:(NSDictionary*)arguments{
NSDictionary *dic = arguments;
_codeId = dic[@"iosId"];
_isFullScreen = [dic[@"isFullScreen"] boolValue];
self.isBidding =[dic[@"isBidding"] boolValue];
_interstitialAd = [[GDTUnifiedInterstitialAd alloc] initWithPlacementId:_codeId];
_interstitialAd.delegate = self;
_interstitialAd.videoMuted = false;
_isFullScreen ? [_interstitialAd loadFullScreenAd] : [_interstitialAd loadAd];
}
//广
- (void)showAd:(NSDictionary*)arguments{
if(self.isBidding){
BOOL isSuccess = [arguments[@"isSuccess"] boolValue];
if(isSuccess){
NSDictionary *dictionary = @{GDT_M_W_E_COST_PRICE:@([arguments[@"expectCostPrice"] intValue]),
GDT_M_W_H_LOSS_PRICE:@([arguments[@"highestLossPrice"] intValue])};
[self.interstitialAd sendWinNotificationWithInfo:dictionary];
if(_isFullScreen){
[_interstitialAd presentFullScreenAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}else{
[_interstitialAd presentAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}
}else{
NSDictionary *dictionary = @{GDT_M_L_WIN_PRICE:@([arguments[@"winPrice"] intValue]),
GDT_M_L_LOSS_REASON:@([arguments[@"lossReason"] intValue]),
GDT_M_ADNID: arguments[@"adnId"]};
[self.interstitialAd sendWinNotificationWithInfo:dictionary];
}
}else{
if(_isFullScreen){
[_interstitialAd presentFullScreenAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}else{
[_interstitialAd presentAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}
}
}
#pragma mark - 广delegate
/**
* 2.0广
* 广
*/
- (void)unifiedInterstitialSuccessToLoadAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告预加载成功回调"];
}
/**
* 2.0广
* 广
*/
- (void)unifiedInterstitialFailToLoadAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error{
[[TLogUtil sharedInstance] print:((void)(@"插屏2.0广告预加载失败回调 %@"),error.description)];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onFail",@"code":@(-1),@"message":error.description};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广
*/
- (void)unifiedInterstitialDidDownloadVideo:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告视频缓存完成"];
}
/**
* 2.0广
* 广
*/
- (void)unifiedInterstitialRenderSuccess:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告渲染成功"];
//
if(self.isBidding){
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onECPM",@"ecpmLevel":self.interstitialAd.eCPMLevel == nil ? @"" : self.interstitialAd.eCPMLevel,@"ecpm":@(self.interstitialAd.eCPM)};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}else{
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onReady"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
}
/**
* 2.0广
*/
- (void)unifiedInterstitialRenderFail:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error{
[[TLogUtil sharedInstance] print:((void)(@"插屏2.0广告渲染失败 %@"),error.description)];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onFail",@"code":@(-1),@"message":error.description};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广
* 2.0广
*/
- (void)unifiedInterstitialWillPresentScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告将要展示回调"];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onShow"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广
* 2.0广
*/
- (void)unifiedInterstitialDidPresentScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告视图展示成功回调"];
}
/**
* 2.0广
* 2.0广
*/
- (void)unifiedInterstitialFailToPresent:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error{
[[TLogUtil sharedInstance] print:((void)(@"插屏2.0广告视图展示失败回调 %@"),error.description)];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onFail",@"code":@(-1),@"message":error.description};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广
* 2.0广
*/
- (void)unifiedInterstitialDidDismissScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告展示结束回调"];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onClose"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* AppAppstore
*/
- (void)unifiedInterstitialWillLeaveApplication:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0点击下载应用时会调用系统程序打开其它App或者Appstore时回调"];
}
/**
* 2.0广
*/
- (void)unifiedInterstitialWillExposure:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告曝光回调"];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onExpose"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广
*/
- (void)unifiedInterstitialClicked:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0广告点击回调"];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onClick"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
* 2.0广广
*/
- (void)unifiedInterstitialAdWillPresentFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"点击插屏2.0广告以后即将弹出全屏广告页"];
}
/**
* 2.0广广
*/
- (void)unifiedInterstitialAdDidPresentFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"点击插屏2.0广告以后弹出全屏广告页"];
}
/**
* 广
*/
- (void)unifiedInterstitialAdWillDismissFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0全屏广告页将要关闭"];
}
/**
* 广
*/
- (void)unifiedInterstitialAdDidDismissFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0全屏广告页将要关闭"];
}
/**
* 2.0广 player
*/
- (void)unifiedInterstitialAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial playerStatusChanged:(GDTMediaPlayerStatus)status{
[[TLogUtil sharedInstance] print:@"插屏2.0视频广告 player 播放状态更新回调"];
}
/**
* 2.0广 WillPresent
*/
- (void)unifiedInterstitialAdViewWillPresentVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0视频广告详情页 WillPresent 回调"];
}
/**
* 2.0广 DidPresent
*/
- (void)unifiedInterstitialAdViewDidPresentVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0视频广告详情页 DidPresent 回调"];
}
/**
* 2.0广 WillDismiss
*/
- (void)unifiedInterstitialAdViewWillDismissVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0视频广告详情页 WillDismiss 回调"];
}
/**
* 2.0广 DidDismiss
*/
- (void)unifiedInterstitialAdViewDidDismissVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
[[TLogUtil sharedInstance] print:@"插屏2.0视频广告详情页 DidDismiss 回调"];
}
/**
* 广广
@param unifiedInterstitial GDTUnifiedInterstitialAd
@param info 广 @{@"GDT_TRANS_ID":@"930f1fc8ac59983bbdf4548ee40ac353"}, @GDT_TRANS_ID广id
*/
- (void)unifiedInterstitialAdDidRewardEffective:(GDTUnifiedInterstitialAd *)unifiedInterstitial info:(NSDictionary *)info{
[[TLogUtil sharedInstance] print:@"插屏激励广告视频播放达到激励条件回调(只有插屏激励广告位才会有此回调)"];
NSString *transId = info[@"GDT_TRANS_ID"];
NSDictionary *dictionary = @{@"adType":@"interactAd",@"onAdMethod":@"onVerify",@"transId":transId};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
@end

View File

@ -0,0 +1,20 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface NaitveAdFactory : NSObject<FlutterPlatformViewFactory>
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messager;
@end
@interface NativeAd : NSObject<FlutterPlatformView>
- (instancetype)initWithWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,255 @@
#import "NativeAd.h"
#import "GDTNativeExpressAd.h"
#import "TLogUtil.h"
#import "TUIViewController+getCurrentVC.h"
#import "GDTNativeExpressAdView.h"
#pragma mark - NaitveAdFactory
@implementation NaitveAdFactory{
NSObject<FlutterBinaryMessenger>*_messenger;
}
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messager{
self = [super init];
if (self) {
_messenger = messager;
}
return self;
}
-(NSObject<FlutterMessageCodec> *)createArgsCodec{
return [FlutterStandardMessageCodec sharedInstance];
}
-(NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args{
NativeAd * nativeAd = [[NativeAd alloc] initWithWithFrame:frame viewIdentifier:viewId arguments:args binaryMessenger:_messenger];
return nativeAd;
}
@end
@interface NativeAd()<GDTNativeExpressAdDelegete>
@property (nonatomic, strong) GDTNativeExpressAd *native;
@property (nonatomic, strong) GDTNativeExpressAdView *nativeView;
@property(nonatomic,strong) UIView *container;
@property(nonatomic,assign) CGRect frame;
@property(nonatomic,assign) NSInteger viewId;
@property(nonatomic,strong) FlutterMethodChannel *channel;
@property(nonatomic,strong) NSString *codeId;
@property(nonatomic,assign) NSInteger viewWidth;
@property(nonatomic,assign) NSInteger viewHeight;
@property(nonatomic,assign) BOOL isBidding;
@end
#pragma mark - NativeAd
@implementation NativeAd
- (instancetype)initWithWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args binaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger{
if ([super init]) {
NSDictionary *dic = args;
_frame = frame;
_viewId = viewId;
_codeId = dic[@"iosId"];
_viewWidth =[dic[@"viewWidth"] intValue];
_viewHeight =[dic[@"viewHeight"] intValue];
self.isBidding =[dic[@"isBidding"] boolValue];
NSString* channelName = [NSString stringWithFormat:@"com.example.union_ad_ssgf/NativeExpressAdView_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
[self.channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
//
if ([@"biddingSucceeded" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_W_E_COST_PRICE:@([call.arguments[@"expectCostPrice"] intValue]),
GDT_M_W_H_LOSS_PRICE:@([call.arguments[@"highestLossPrice"] intValue])};
[self.native sendWinNotificationWithInfo:dictionary];
[_container addSubview:self.nativeView];
[self.nativeView render];
//
} else if([@"biddingFail" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_L_WIN_PRICE:@([call.arguments[@"winPrice"] intValue]),
GDT_M_L_LOSS_REASON:@([call.arguments[@"lossReason"] intValue]),
GDT_M_ADNID: call.arguments[@"adnId"]};
[self.native sendWinNotificationWithInfo:dictionary];
}
}];
_container = [[UIView alloc] initWithFrame:frame];
[self loadNativeAd];
}
return self;
}
- (UIView*)view{
return _container;
}
-(void)loadNativeAd{
[_container removeFromSuperview];
CGSize size = CGSizeMake(_viewWidth, _viewHeight);
if(_native == nil){
_native =[[GDTNativeExpressAd alloc] initWithPlacementId:_codeId adSize:size];
_native.delegate = self;
}
[_native loadAd:1];
}
#pragma mark - 广delegate
/**
* 广
*/
- (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd *)nativeExpressAd views:(NSArray<__kindof GDTNativeExpressAdView *> *)views{
[[TLogUtil sharedInstance] print:@"拉取原生模板广告成功"];
if (views.count) {
[views enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
self.nativeView = (GDTNativeExpressAdView *)obj;
self.nativeView.controller = [UIViewController jsd_getCurrentViewController];
//
if(self.isBidding){
NSDictionary *dictionary = @{@"ecpmLevel":self.nativeView.eCPMLevel == nil ? @"" : self.nativeView.eCPMLevel,@"ecpm":@(self.nativeView.eCPM)};
[_channel invokeMethod:@"onECPM" arguments:dictionary result:nil];
}else{
[_container addSubview:self.nativeView];
[self.nativeView render];
}
}];
}
}
/**
* 广
*/
- (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{
[[TLogUtil sharedInstance] print:(@"拉取原生模板广告失败 %@",error.description)];
NSDictionary *dictionary = @{@"code":@(-1),@"message":(@"%@",error.description)};
[_channel invokeMethod:@"onFail" arguments:dictionary result:nil];
}
/**
* 广, nativeExpressAdView.size.height size.width
*/
- (void)nativeExpressAdViewRenderSuccess:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生模板广告渲染成功"];
NSDictionary *dictionary = @{@"width": @(nativeExpressAdView.frame.size.width),@"height":@(nativeExpressAdView.frame.size.height)};
[_channel invokeMethod:@"onShow" arguments:dictionary result:nil];
}
/**
* 广
*/
- (void)nativeExpressAdViewRenderFail:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生模板广告渲染失败"];
NSDictionary *dictionary = @{@"code":@(-1),@"message":@"原生模板广告渲染失败"};
[_channel invokeMethod:@"onFail" arguments:dictionary result:nil];
}
/**
* 广
*/
- (void)nativeExpressAdViewExposure:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生模板广告曝光回调"];
[_channel invokeMethod:@"onExpose" arguments:nil result:nil];
}
/**
* 广
*/
- (void)nativeExpressAdViewClicked:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生模板广告点击回调"];
[_channel invokeMethod:@"onClick" arguments:nil result:nil];
}
/**
* 广
*/
- (void)nativeExpressAdViewClosed:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生模板广告被关闭"];
[_channel invokeMethod:@"onClose" arguments:nil result:nil];
}
/**
* 广广
*/
- (void)nativeExpressAdViewWillPresentScreen:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"点击原生模板广告以后即将弹出全屏广告页"];
}
/**
* 广广
*/
- (void)nativeExpressAdViewDidPresentScreen:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"点击原生模板广告以后弹出全屏广告页"];
}
/**
* 广
*/
- (void)nativeExpressAdViewWillDismissScreen:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"全屏广告页将要关闭"];
}
/**
* 广
*/
- (void)nativeExpressAdViewDidDismissScreen:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"全屏广告页将要关闭"];
}
/**
* :广
*/
- (void)nativeExpressAdViewApplicationWillEnterBackground:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"详解:当点击应用下载或者广告调用系统程序打开时调用"];
}
/**
* 广 player
*/
- (void)nativeExpressAdView:(GDTNativeExpressAdView *)nativeExpressAdView playerStatusChanged:(GDTMediaPlayerStatus)status{
[[TLogUtil sharedInstance] print:@"原生模板视频广告 player 播放状态更新回调"];
}
/**
* WillPresent
*/
- (void)nativeExpressAdViewWillPresentVideoVC:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生视频模板详情页 WillPresent 回调"];
}
/**
* DidPresent
*/
- (void)nativeExpressAdViewDidPresentVideoVC:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@"原生视频模板详情页 DidPresent 回调"];
}
/**
* WillDismiss
*/
- (void)nativeExpressAdViewWillDismissVideoVC:(GDTNativeExpressAdView *)nativeExpressAdView{
[[TLogUtil sharedInstance] print:@" 原生视频模板详情页 WillDismiss 回调"];
}
/**
* DidDismiss
*/
- (void)nativeExpressAdViewDidDismissVideoVC:(GDTNativeExpressAdView *)nativeExpressAdView;{
[[TLogUtil sharedInstance] print:@"原生视频模板详情页 DidDismiss 回调"];
}
@end

View File

@ -0,0 +1,13 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface RewardAd : NSObject
+ (instancetype)sharedInstance;
- (void)initAd:(NSDictionary *)arguments;
- (void)showAd:(NSDictionary *)arguments;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,201 @@
#import "RewardAd.h"
#import "GDTRewardVideoAd.h"
#import "UnionAdSsgfEvent.h"
#import "TLogUtil.h"
#import "TUIViewController+getCurrentVC.h"
@interface RewardAd()<GDTRewardedVideoAdDelegate>
@property(nonatomic,strong) GDTRewardVideoAd *reward;
@property(nonatomic,strong) NSString *codeId;
@property(nonatomic,strong) NSString *rewardName;
@property(nonatomic,strong) NSString *rewardAmount;
@property(nonatomic,strong) NSString *userID;
@property(nonatomic,strong) NSString *customData;
@property(nonatomic,assign) BOOL isBidding;
@end
@implementation RewardAd
+ (instancetype)sharedInstance{
static RewardAd *myInstance = nil;
if(myInstance == nil){
myInstance = [[RewardAd alloc]init];
}
return myInstance;
}
//广
-(void)initAd:(NSDictionary*)arguments{
NSDictionary *dic = arguments;
_codeId = dic[@"iosId"];
_rewardName = dic[@"rewardName"];
_rewardAmount = dic[@"rewardAmount"];
_userID =dic[@"userID"];
_customData = dic[@"customData"];
_reward = [[GDTRewardVideoAd alloc] initWithPlacementId:_codeId];
_reward.delegate = self;
_reward.videoMuted = dic[@"videoMuted"];
self.isBidding =[dic[@"isBidding"] boolValue];
GDTServerSideVerificationOptions *options = [[GDTServerSideVerificationOptions alloc] init];
options.userIdentifier = _userID;
options.customRewardString = _customData;
_reward.serverSideVerificationOptions = options;
[_reward loadAd];
}
//广
-(void)showAd:(NSDictionary*)arguments{
if (_reward.expiredTimestamp <= [[NSDate date] timeIntervalSince1970]) {
[[TLogUtil sharedInstance] print:(@"广告已过期,请重新拉取")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onFail",@"code":@(-1),@"message":@"广告已过期,请重新拉取"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
return;
}
if (!_reward.isAdValid) {
[[TLogUtil sharedInstance] print:(@"广告失效,请重新拉取")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onFail",@"code":@(-1),@"message":@"广告失效,请重新拉取"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
return;
}
if(self.isBidding){
BOOL isSuccess = [arguments[@"isSuccess"] boolValue];
if(isSuccess){
NSDictionary *dictionary = @{GDT_M_W_E_COST_PRICE:@([arguments[@"expectCostPrice"] intValue]),
GDT_M_W_H_LOSS_PRICE:@([arguments[@"highestLossPrice"] intValue])};
[self.reward sendWinNotificationWithInfo:dictionary];
[self.reward showAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}else{
NSDictionary *dictionary = @{GDT_M_L_WIN_PRICE:@([arguments[@"winPrice"] intValue]),
GDT_M_L_LOSS_REASON:@([arguments[@"lossReason"] intValue]),
GDT_M_ADNID: arguments[@"adnId"]};
[self.reward sendWinNotificationWithInfo:dictionary];
}
}else{
[self.reward showAdFromRootViewController:[UIViewController jsd_getCurrentViewController]];
}
}
#pragma mark - 广delegate
/**
广
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidLoad:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告数据加载成功")];
//
if(self.isBidding){
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onECPM",@"ecpmLevel":self.reward.eCPMLevel == nil ? @"" : self.reward.eCPMLevel,@"ecpm":@(self.reward.eCPM)};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}else{
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onReady"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
}
/**
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdVideoDidLoad:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告视频数据下载成功")];
}
/**
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdWillVisible:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告视频播放页即将展示回调")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onShow"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidExposed:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告曝光")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onExpose"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidClose:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告关闭")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onClose"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidClicked:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告点击")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onClick"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
@param error
*/
- (void)gdt_rewardVideoAd:(GDTRewardVideoAd *)rewardedVideoAd didFailWithError:(NSError *)error{
[[TLogUtil sharedInstance] print:((void)(@"激励广告错误,%@"),error.description)];
NSInteger code = error.code;
NSString *message = error.description;
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onFail",@"code":@(code),@"message":message};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidRewardEffective:(GDTRewardVideoAd *)rewardedVideoAd GDT_DEPRECATED_MSG_ATTRIBUTE("接口即将废弃,请使用 gdt_rewardVideoAdDidRewardEffective:info:"){
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
@param info 广 @{@"GDT_TRANS_ID":@"930f1fc8ac59983bbdf4548ee40ac353"}, @GDT_TRANS_ID广id
*/
- (void)gdt_rewardVideoAdDidRewardEffective:(GDTRewardVideoAd *)rewardedVideoAd info:(NSDictionary *)info{
[[TLogUtil sharedInstance] print:(@"激励广告视频广告播放达到激励条件")];
NSString *transId = info[@"GDT_TRANS_ID"];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onVerify",@"transId":transId,@"rewardAmount":_rewardAmount,@"rewardName":_rewardName};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
/**
广
@param rewardedVideoAd GDTRewardVideoAd
*/
- (void)gdt_rewardVideoAdDidPlayFinish:(GDTRewardVideoAd *)rewardedVideoAd{
[[TLogUtil sharedInstance] print:(@"激励广告视频广告视频播放完成")];
NSDictionary *dictionary = @{@"adType":@"rewardAd",@"onAdMethod":@"onFinish"};
[[UnionAdSsgfEvent sharedInstance] sentEvent:dictionary];
}
@end

View File

@ -0,0 +1,22 @@
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface SplashAdFactory : NSObject<FlutterPlatformViewFactory>
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger>*)messager;
@end
@interface SplashAd : NSObject<FlutterPlatformView>
- (instancetype)initWithWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,199 @@
#import "SplashAd.h"
#import "GDTSplashAd.h"
#import "TLogUtil.h"
@implementation SplashAdFactory{
NSObject<FlutterBinaryMessenger>*_messenger;
}
- (instancetype)initWithMessenger:(NSObject<FlutterBinaryMessenger> *)messager{
self = [super init];
if (self) {
_messenger = messager;
}
return self;
}
-(NSObject<FlutterMessageCodec> *)createArgsCodec{
return [FlutterStandardMessageCodec sharedInstance];
}
-(NSObject<FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args{
SplashAd * splashAd = [[SplashAd alloc] initWithWithFrame:frame viewIdentifier:viewId arguments:args binaryMessenger:_messenger];
return splashAd;
}
@end
@interface SplashAd()<GDTSplashAdDelegate>
@property (nonatomic, strong) GDTSplashAd *splash;
@property(nonatomic,strong) UIView *container;
@property(nonatomic,assign) CGRect frame;
@property(nonatomic,assign) NSInteger viewId;
@property(nonatomic,strong) FlutterMethodChannel *channel;
@property(nonatomic,strong) NSString *codeId;
@property(nonatomic,assign) NSInteger fetchDelay;
@property(nonatomic,assign) BOOL isBidding;
@end
@implementation SplashAd
- (instancetype)initWithWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id)args binaryMessenger:(NSObject<FlutterBinaryMessenger> *)messenger{
if ([super init]) {
NSDictionary *dic = args;
_frame = frame;
_viewId = viewId;
_codeId = dic[@"iosId"];
_fetchDelay =[dic[@"_fetchDelay"] intValue];
self.isBidding =[dic[@"isBidding"] boolValue];
NSString* channelName = [NSString stringWithFormat:@"com.example.union_ad_ssgf/SplashAdView_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
[self.channel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
//
if ([@"biddingSucceeded" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_W_E_COST_PRICE:@([call.arguments[@"expectCostPrice"] intValue]),
GDT_M_W_H_LOSS_PRICE:@([call.arguments[@"highestLossPrice"] intValue])};
[self.splash sendWinNotificationWithInfo:dictionary];
//广
[self.splash showFullScreenAdInWindow:[UIApplication sharedApplication].keyWindow withLogoImage:nil skipView:nil];
//
} else if([@"biddingFail" isEqualToString:call.method]) {
NSDictionary *dictionary = @{GDT_M_L_WIN_PRICE:@([call.arguments[@"winPrice"] intValue]),
GDT_M_L_LOSS_REASON:@([call.arguments[@"lossReason"] intValue]),
GDT_M_ADNID: call.arguments[@"adnId"]};
[self.splash sendWinNotificationWithInfo:dictionary];
}
}];
[self loadSplashAd];
}
return self;
}
- (UIView*)view{
return _container;
}
-(void)loadSplashAd{
_splash = [[GDTSplashAd alloc] initWithPlacementId:_codeId];
_splash.delegate = self;
_splash.fetchDelay = _fetchDelay;
[_splash loadFullScreenAd];
}
#pragma mark - 广delegate
/**
* 广
*/
- (void)splashAdSuccessPresentScreen:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告成功展示"];
[_channel invokeMethod:@"onShow" arguments:nil result:nil];
}
/**
* 广
*/
- (void)splashAdDidLoad:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告素材加载成功"];
if(!splashAd.isAdValid){
[[TLogUtil sharedInstance] print:@"开屏广告展示失败"];
NSDictionary *dictionary = @{@"code":@(-1),@"message":@"广告展示失败"};
[_channel invokeMethod:@"onFail" arguments:dictionary result:nil];
return;
}
//
if(self.isBidding){
NSDictionary *dictionary = @{@"ecpmLevel":self.splash.eCPMLevel == nil ? @"" : self.splash.eCPMLevel,@"ecpm":@(self.splash.eCPM)};
[_channel invokeMethod:@"onECPM" arguments:dictionary result:nil];
}else{
[self.splash showFullScreenAdInWindow:[UIApplication sharedApplication].keyWindow withLogoImage:nil skipView:nil];
}
}
/**
* 广
*/
- (void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error{
[[TLogUtil sharedInstance] print:@"开屏广告展示失败"];
NSDictionary *dictionary = @{@"code":@(-1),@"message":((void)(@"广告展示失败%@"),error.description)};
[_channel invokeMethod:@"onFail" arguments:dictionary result:nil];
}
/**
*
* :
*/
- (void)splashAdApplicationWillEnterBackground:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"应用进入后台时回调"];
}
/**
* 广
*/
- (void)splashAdExposured:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@" 开屏广告曝光回调"];
[_channel invokeMethod:@"onExpose" arguments:nil result:nil];
}
/**
* 广
*/
- (void)splashAdClicked:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告点击回调"];
[_channel invokeMethod:@"onClick" arguments:nil result:nil];
}
/**
* 广
*/
- (void)splashAdWillClosed:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告将要关闭回调"];
[_channel invokeMethod:@"onClose" arguments:nil result:nil];
}
/**
* 广
*/
- (void)splashAdClosed:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告关闭回调"];
}
/**
* 广广
*/
- (void)splashAdWillPresentFullScreenModal:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告点击以后即将弹出全屏广告页"];
}
/**
* 广广
*/
- (void)splashAdDidPresentFullScreenModal:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"开屏广告点击以后弹出全屏广告页"];
}
/**
* 广
*/
- (void)splashAdWillDismissFullScreenModal:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@"点击以后全屏广告页将要关闭"];
}
/**
* 广
*/
- (void)splashAdDidDismissFullScreenModal:(GDTSplashAd *)splashAd{
[[TLogUtil sharedInstance] print:@" 点击以后全屏广告页已经关闭"];
}
/**
* 广
*/
- (void)splashAdLifeTime:(NSUInteger)time;{
NSString *timeStr =[NSString stringWithFormat:@"开屏广告剩余时间回调%lu",(unsigned long)time];
[[TLogUtil sharedInstance] print:timeStr];
}
@end

View File

@ -0,0 +1,15 @@
#ifdef DEBUG
#define GLog(...) NSLog(@"%s\n %@\n\n", __func__, [NSString stringWithFormat:__VA_ARGS__])
#else
#define GLog(...)
#endif
NS_ASSUME_NONNULL_BEGIN
@interface TLogUtil : NSObject
+ (instancetype)sharedInstance;
- (void)debug:(BOOL)isDebug;
- (void)print:(NSString *)message;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,29 @@
#import <Foundation/Foundation.h>
#import "TLogUtil.h"
@interface TLogUtil()
@property(nonatomic,assign) BOOL isDebug;
@end
@implementation TLogUtil
+ (instancetype)sharedInstance{
static TLogUtil *myInstance = nil;
if(myInstance == nil){
myInstance = [[TLogUtil alloc]init];
}
return myInstance;
}
- (void)debug:(BOOL)isDebug{
_isDebug = isDebug;
}
- (void)print:(NSString *)message{
if(_isDebug){
GLog(@"%@", message);
}
}
@end

View File

@ -0,0 +1,19 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface UIViewController (getCurrentVC)<UIViewControllerAnimatedTransitioning>
+ (UIViewController *)jsd_getCurrentViewController;
+ (UIViewController *)jsd_getRootViewController;
+ (UIViewController *)getCurrentVCWithCurrentView:(UIView *)currentView;
+(UITabBarController *)currentTtabarController;
+(UINavigationController *)currentTabbarSelectedNavigationController;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,89 @@
#import "TUIViewController+getCurrentVC.h"
@implementation UIViewController (getCurrentVC)
+ (UIViewController *)jsd_getRootViewController{
UIWindow* window = [[[UIApplication sharedApplication] delegate] window];
//NSAssert(window, @"The window is empty");
return window.rootViewController;
}
+ (UIViewController *)jsd_getCurrentViewController{
UIViewController* currentViewController = [self jsd_getRootViewController];
BOOL runLoopFind = YES;
while (runLoopFind) {
if (currentViewController.presentedViewController) {
currentViewController = currentViewController.presentedViewController;
} else if ([currentViewController isKindOfClass:[UINavigationController class]]) {
UINavigationController* navigationController = (UINavigationController* )currentViewController;
currentViewController = [navigationController.childViewControllers lastObject];
} else if ([currentViewController isKindOfClass:[UITabBarController class]]) {
UITabBarController* tabBarController = (UITabBarController* )currentViewController;
currentViewController = tabBarController.selectedViewController;
} else {
NSUInteger childViewControllerCount = currentViewController.childViewControllers.count;
if (childViewControllerCount > 0) {
currentViewController = currentViewController.childViewControllers.lastObject;
return currentViewController;
} else {
return currentViewController;
}
}
}
return currentViewController;
}
+ (UIViewController *)getCurrentVCWithCurrentView:(UIView *)currentView
{
for (UIView *next = currentView ; next ; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)nextResponder;
}
}
return nil;
}
+(UITabBarController *)currentTtabarController
{
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
UIViewController *tabbarController = window.rootViewController;
if ([tabbarController isKindOfClass:[UITabBarController class]]) {
return (UITabBarController *)tabbarController;
}
return nil;
}
+(UINavigationController *)currentTabbarSelectedNavigationController
{
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
UIViewController *rootVC = window.rootViewController;
if ([rootVC isKindOfClass:[UINavigationController class]]) {
return (UINavigationController *)rootVC;
}else if([rootVC isKindOfClass:[UITabBarController class]]){
UITabBarController *tabarController = [self currentTtabarController];
UINavigationController *selectedNV = (UINavigationController *)tabarController.selectedViewController;
if ([selectedNV isKindOfClass:[UINavigationController class]]) {
return selectedNV;
}
}
return nil;
}
@end