-
Notifications
You must be signed in to change notification settings - Fork 3
/
CustomBidInMobiInterstitialAdapter.m
191 lines (154 loc) · 4.6 KB
/
CustomBidInMobiInterstitialAdapter.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#import "CustomBidInMobiInterstitialAdapter.h"
#import <TradPlusAds/MSLogging.h>
#import <TradPlusAds/MsCommon.h>
#import <TradPlusAds/TradPlusAdWaterfallItem.h>
#import <InMobiSDK/InMobiSDK.h>
@interface CustomBidInMobiInterstitialAdapter ()<IMInterstitialDelegate>
@property (nonatomic,strong)IMInterstitial *interstitial;
@property (nonatomic,copy)NSString *placementId;
@end
@implementation CustomBidInMobiInterstitialAdapter
#pragma mark - Extra
//根据event实现相关流程
- (BOOL)extraActWithEvent:(NSString *)event info:(NSDictionary *)config
{
if([event isEqualToString:@"C2SBidding"])
{
//从三方SDK获取价格
[self getECPMC2SBidding];
}
else if([event isEqualToString:@"LoadAdC2SBidding"])
{
//竞价成功后的加载流程
[self loadAdC2SBidding];
}
else
{
return NO;
}
return YES;
}
#pragma mark - C2SBidding
//从三方SDK获取价格
- (void)getECPMC2SBidding
{
NSString *account_id = self.waterfallItem.config[@"account_id"];
self.placementId = self.waterfallItem.config[@"placementId"];
if(account_id == nil || [account_id isKindOfClass:[NSNull class]] || self.placementId == nil)
{
MSLogTrace(@"InMobi init Config Error %@",self.waterfallItem.config);
[self AdConfigError];
return;
}
//先进行三方SDK的初始化,如已初始化则可以不调用
__weak typeof(self) weakSelf = self;
[IMSdk initWithAccountID:account_id andCompletionHandler:^(NSError * _Nullable error) {
[weakSelf startC2SBidding];
}];
}
//通过三方API获取ECPM
- (void)startC2SBidding
{
self.interstitial = [[IMInterstitial alloc] initWithPlacementId:[self.placementId longLongValue]];
self.interstitial.delegate = self;
[self.interstitial.preloadManager preload];
}
//获取ECPM成功
- (void)finishC2SBiddingWithMetaInfo:(IMAdMetaInfo*)info
{
//三方版本号
NSString *version = [IMSdk getVersion];
if(version == nil)
{
version = @"";
}
//通过接口向TradPlusSDK回传ecpm和三方版本号
NSString *ecpmStr = [NSString stringWithFormat:@"%f",info.getBid];
NSDictionary *dic = @{@"ecpm":ecpmStr,@"version":version};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFinish" info:dic];
}
//获取ECPM失败
- (void)failC2SBiddingWithErrorStr:(NSString *)errorStr
{
NSDictionary *dic = @{@"error":errorStr};
[self ADLoadExtraCallbackWithEvent:@"C2SBiddingFail" info:dic];
}
//通过三方API加载广告
- (void)loadAdC2SBidding
{
[self.interstitial.preloadManager load];
}
//展示
- (void)showAdFromRootViewController:(UIViewController *)rootViewController
{
[self.interstitial showFrom:rootViewController];
}
- (BOOL)isReady
{
return (self.interstitial != nil && self.interstitial.isReady);
}
#pragma mark - IMInterstitialDelegate
-(void)interstitial:(IMInterstitial*)interstitial didReceiveWithMetaInfo:(IMAdMetaInfo*)metaInfo
{
//ECPM获取成功
[self finishC2SBiddingWithMetaInfo:metaInfo];
}
-(void)interstitial:(IMInterstitial*)interstitial didFailToReceiveWithError:(NSError*)error
{
//ECPM获取失败
NSString *errorStr = @"C2S Bidding Fail";
if(error != nil)
{
errorStr = [NSString stringWithFormat:@"errCode: %ld, errMsg: %@", (long)error.code, error.localizedDescription];
}
[self failC2SBiddingWithErrorStr:errorStr];
}
-(void)interstitialDidFinishLoading:(IMInterstitial*)interstitial
{
//加载成功
[self AdLoadFinsh];
}
-(void)interstitial:(IMInterstitial*)interstitial didFailToLoadWithError:(IMRequestStatus *)error
{
//加载失败
[self AdLoadFailWithError:error];
}
-(void)interstitialDidDismiss:(IMInterstitial*)interstitial
{
//广告关闭
[self AdClose];
}
-(void)interstitialAdImpressed:(IMInterstitial*)interstitial
{
//展示成功
[self AdShow];
}
-(void)interstitial:(IMInterstitial*)interstitial didFailToPresentWithError:(IMRequestStatus*)error
{
//展示失败
[self AdShowFailWithError:error];
}
-(void)interstitial:(IMInterstitial*)interstitial didInteractWithParams:(NSDictionary*)params
{
//点击
[self AdClick];
}
-(void)interstitialDidPresent:(IMInterstitial*)interstitial
{
}
-(void)interstitial:(IMInterstitial*)interstitial gotSignals:(NSData*)signals
{
}
-(void)interstitial:(IMInterstitial*)interstitial failedToGetSignalsWithError:(IMRequestStatus*)status
{
}
-(void)interstitialWillPresent:(IMInterstitial*)interstitial
{
}
-(void)interstitialWillDismiss:(IMInterstitial*)interstitial
{
}
-(void)userWillLeaveApplicationFromInterstitial:(IMInterstitial*)interstitial
{
}
@end