Commit 93c765ca authored by zhangshuai's avatar zhangshuai

优化 广告bug

parent f19e326b
...@@ -357,6 +357,7 @@ static CGNetworkTools* _tools = nil; ...@@ -357,6 +357,7 @@ static CGNetworkTools* _tools = nil;
if ([[data Read] objectForKey:@"source"]) { if ([[data Read] objectForKey:@"source"]) {
[dict setValue: [[data Read] objectForKey:@"source"] forKey: @"source"]; [dict setValue: [[data Read] objectForKey:@"source"] forKey: @"source"];
} }
[dict setValue: @"toutiao" forKey: @"source"];
NSString *uid = [[data Read] objectForKey:@"uid"]; NSString *uid = [[data Read] objectForKey:@"uid"];
if (uid != nil) { [dict setValue: uid forKey: @"uid"]; } if (uid != nil) { [dict setValue: uid forKey: @"uid"]; }
......
...@@ -213,9 +213,11 @@ static IOSADManager * manager = nil; ...@@ -213,9 +213,11 @@ static IOSADManager * manager = nil;
/// @param loadADModel 广告对象 /// @param loadADModel 广告对象
/// @param AdType 广告类型 /// @param AdType 广告类型
- (void)loadAdWithData:(GYAdsTrackModel *)loadADModel withADType:(eADType )AdType;{ - (void)loadAdWithData:(GYAdsTrackModel *)loadADModel withADType:(eADType )AdType;{
NSLog(@">>>>>>> 准备缓存 平台 = %@ ID = %@ type= %@ <<<<<<<<<",loadADModel.adPlatform,loadADModel.codeId,loadADModel.slotName);
self.haveLodeAD = YES; self.haveLodeAD = YES;
loadADModel.loadADType = AdType; loadADModel.loadADType = AdType;
if ([self.loadADDataArray count] > 6) { if ([self.loadADDataArray count] > 10) {
[self.loadADDataArray removeObject:self.loadADDataArray.firstObject]; [self.loadADDataArray removeObject:self.loadADDataArray.firstObject];
} }
WEAKSELF; WEAKSELF;
...@@ -231,20 +233,21 @@ static IOSADManager * manager = nil; ...@@ -231,20 +233,21 @@ static IOSADManager * manager = nil;
time = 5; time = 5;
} }
// 去加载 // 去加载
weakSelf.csjAd = nil;
AddCSJADManager * csjAd = [[AddCSJADManager alloc]init];
weakSelf.csjAd = csjAd;
[weakSelf.loadADDataArray addObject:csjAd];
[csjAd loadAdWithData:loadADModel withADType:AdType];
csjAd.loadSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) {
[weakSelf blockResultLoadWithData:model andSuccess:success];
};
csjAd.showSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) {
[weakSelf blockResultShowWithData:model andSuccess:YES];
};
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.csjAd = nil;
AddCSJADManager * csjAd = [[AddCSJADManager alloc]init];
self.csjAd = csjAd;
[self.loadADDataArray addObject:csjAd];
[csjAd loadAdWithData:loadADModel withADType:AdType];
csjAd.loadSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) {
[weakSelf blockResultLoadWithData:model andSuccess:success];
};
csjAd.showSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) {
[weakSelf blockResultShowWithData:model andSuccess:YES];
};
}); });
} }
...@@ -312,27 +315,31 @@ static IOSADManager * manager = nil; ...@@ -312,27 +315,31 @@ static IOSADManager * manager = nil;
} }
}else{ }else{
if (AdType == ADType_Video) { // 视频 if (AdType == ADType_Video) { // 视频
if (self.videoModels.count > self.cachevideo.count) {
GYAdsTrackModel * adData = loadADModel; GYAdsTrackModel * adData = self.videoModels[self.cachevideo.count];
NSLog(@">>>>>>> 缓存 失败 %@ 不支持",adData.adPlatform);
if (adData.firstFailure == NO) {
adData.firstFailure = YES;
}else{
[adData.backups removeObject:adData.backups.firstObject];
}
if (adData.backups.count) {
[self loadAdWithData:adData.backups.firstObject withADType:AdType];
}else{
[self.videoModels removeObject:loadADModel];
if (self.videoModels.count) { NSLog(@">>>>>>> 缓存 失败 %@ 不支持",adData.adPlatform);
[self loadAdWithData:self.videoModels.firstObject withADType:AdType]; if (adData.firstFailure == NO) {
adData.firstFailure = YES;
}else{ }else{
[self requestVideoAD]; [adData.backups removeObject:adData.backups.firstObject];
} }
if (adData.backups.count) {
[self loadAdWithData:adData.backups.firstObject withADType:AdType];
}else{
[self.videoModels removeObject:loadADModel];
if (self.videoModels.count) {
[self loadAdWithData:self.videoModels.firstObject withADType:AdType];
}else{
[self requestVideoAD];
}
}
}else{
[self requestVideoAD];
} }
}else if (AdType == ADType_OpenScreen){ }else if (AdType == ADType_OpenScreen){
...@@ -375,27 +382,26 @@ static IOSADManager * manager = nil; ...@@ -375,27 +382,26 @@ static IOSADManager * manager = nil;
/// @param adType 广告类型 /// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{ - (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
if (adType == ADType_Video) { // 视频 if (adType == ADType_Video) { // 视频
NSLog(@">>>>>>> 正在播放 成功 平台 = %@ ID = %@ <<<<<<<<<",showData.adPlatform,showData.codeId); NSLog(@">>>>>>> 正在播放 成功 平台 = %@ ID = %@ type =%@ <<<<<<<<<",showData.adPlatform,showData.codeId,showData.slotName);
WEAKSELF; WEAKSELF;
if ([showData.adPlatform isEqualToString:@"chuanshanjia"]) { dispatch_async(dispatch_get_main_queue(), ^{
[self.csjAd showAdWithData:showData withADType:adType]; if ([showData.adPlatform isEqualToString:@"chuanshanjia"]) {
[weakSelf.csjAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"guangdiantong"]){
[self.gdtAd showAdWithData:showData withADType:adType]; }else if ([showData.adPlatform isEqualToString:@"guangdiantong"]){
[weakSelf.gdtAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"sigmob"]){ }else if ([showData.adPlatform isEqualToString:@"sigmob"]){
[self.sigmobAd showAdWithData:showData withADType:adType]; [weakSelf.sigmobAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"ruishi"]){ }else if ([showData.adPlatform isEqualToString:@"ruishi"]){
[self.ruishiAd showAdWithData:showData withADType:adType]; [weakSelf.ruishiAd showAdWithData:showData withADType:adType];
} }
});
if (self.videoModels.count <= 1) { if (weakSelf.videoModels.count <= 1) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weakSelf requestVideoAD];
[weakSelf requestVideoAD];
});
}else{ }else{
[self loadAdWithData:self.videoModels[1] withADType:ADType_Video]; [weakSelf loadAdWithData:weakSelf.videoModels[1] withADType:ADType_Video];
} }
}else if (adType == ADType_BigImage){ //大图 }else if (adType == ADType_BigImage){ //大图
...@@ -423,8 +429,9 @@ static IOSADManager * manager = nil; ...@@ -423,8 +429,9 @@ static IOSADManager * manager = nil;
- (void)requestOpenScreenAD;{ - (void)requestOpenScreenAD;{
WEAKSELF; WEAKSELF;
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"splash"} success:^(id _Nonnull response) { [[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"splash"} success:^(id _Nonnull response) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) { if ([[response objectForKey:@"status"] intValue] == 200) {
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_success"]; [[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_success"];
NSMutableArray * models = [NSMutableArray new]; NSMutableArray * models = [NSMutableArray new];
...@@ -452,8 +459,9 @@ static IOSADManager * manager = nil; ...@@ -452,8 +459,9 @@ static IOSADManager * manager = nil;
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"]; [[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"];
} }
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"]; [[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"];
}]; }];
} }
...@@ -461,8 +469,9 @@ static IOSADManager * manager = nil; ...@@ -461,8 +469,9 @@ static IOSADManager * manager = nil;
- (void)requestNativeAD;{ - (void)requestNativeAD;{
WEAKSELF; WEAKSELF;
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_bigimage"} success:^(id _Nonnull response) { [[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_bigimage"} success:^(id _Nonnull response) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) { if ([[response objectForKey:@"status"] intValue] == 200) {
[[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_success"]; [[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_success"];
...@@ -490,8 +499,9 @@ static IOSADManager * manager = nil; ...@@ -490,8 +499,9 @@ static IOSADManager * manager = nil;
} }
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
[[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_failed"]; [[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_failed"];
}]; }];
...@@ -510,8 +520,9 @@ static IOSADManager * manager = nil; ...@@ -510,8 +520,9 @@ static IOSADManager * manager = nil;
} }
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_video"} success:^(id _Nonnull response) { [[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_video"} success:^(id _Nonnull response) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) { if ([[response objectForKey:@"status"] intValue] == 200) {
requestToTry = 0; requestToTry = 0;
...@@ -551,12 +562,14 @@ static IOSADManager * manager = nil; ...@@ -551,12 +562,14 @@ static IOSADManager * manager = nil;
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"]; [[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"];
} }
} failure:^(NSError * _Nonnull error) { } failure:^(NSError * _Nonnull error) {
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
requestToTry += 1; requestToTry += 1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf requestVideoAD]; // [weakSelf requestVideoAD];
}); // });
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"]; [[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"];
}]; }];
...@@ -573,25 +586,60 @@ static IOSADManager * manager = nil; ...@@ -573,25 +586,60 @@ static IOSADManager * manager = nil;
model.cacheDate = [NSDate date]; // 缓存成功时间 model.cacheDate = [NSDate date]; // 缓存成功时间
}else{ }else{
[self trackingADWith:model.pullfail_tracking.firstObject]; [self trackingADWith:model.pullfail_tracking.firstObject];
NSLog(@">>>>>>> 缓存 失败 平台 = %@ ID = %@ type= %@ <<<<<<<<<",model.adPlatform,model.codeId,model.slotName); NSLog(@">>>>>>> 缓存 失败 平台 = %@ ID = %@ type= %@ <<<<<<<<<",model.adPlatform,model.codeId,model.slotName);
} }
if(model.loadADType == ADType_Video){ if(model.loadADType == ADType_Video){
weakSelf.haveLodeAD = NO; weakSelf.haveLodeAD = NO;
[MBProgressHUD hideHUD]; dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if (success) { if (success) {
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_success"]; [[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_success"];
[weakSelf.cachevideo addObject:model]; [weakSelf.cachevideo addObject:model];
if(weakSelf.showNow){ if(weakSelf.showNow){
[weakSelf showADType:ADType_Video resultBlock:self.adShowBlock]; [weakSelf showADType:ADType_Video resultBlock:weakSelf.adShowBlock];
} }
}else{ }else{
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_failed"]; if (weakSelf.videoModels.count > weakSelf.cachevideo.count) {
[weakSelf clearCache:model]; GYAdsTrackModel * firstData = weakSelf.videoModels[weakSelf.cachevideo.count];
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_failed"];
if (firstData.firstFailure == NO) {
firstData.firstFailure = YES;
}else{
[firstData.backups removeObject:firstData.backups.firstObject];
}
if (firstData.backups.count) {
[weakSelf loadAdWithData:firstData.backups.firstObject withADType:ADType_Video];
}else{
[weakSelf.videoModels removeObject:firstData];
if (weakSelf.videoModels.count) {
[weakSelf loadAdWithData:weakSelf.videoModels.firstObject withADType:ADType_Video];
}else{
[weakSelf requestVideoAD];
}
}
}else{
[weakSelf requestVideoAD];
}
} }
// dispatch_queue_t queueglobal = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0);
//
// dispatch_async(queueglobal, ^{
//
// });
}else if(model.loadADType == ADType_OpenScreen){ }else if(model.loadADType == ADType_OpenScreen){
if(success){ if(success){
......
...@@ -72,17 +72,21 @@ ...@@ -72,17 +72,21 @@
/// @param adType 广告类型 /// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{ - (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
if (adType == ADType_OpenScreen) { // 开屏 dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频
if (self.rewardedAd.isAdValid) { }else if (adType == ADType_Video){ //视频
[self.rewardedAd showAdFromRootViewController:self.currentVC]; if (self.rewardedAd.isAdValid) {
}else{ [self.rewardedAd showAdFromRootViewController:self.currentVC];
self.showSuccessCallbackBlock(showData, NO); }else{
self.showSuccessCallbackBlock(showData, NO);
}
}else if (adType == ADType_BigImage){ //大图
} }
}else if (adType == ADType_BigImage){ //大图 });
}
} }
......
...@@ -66,18 +66,20 @@ ...@@ -66,18 +66,20 @@
/// @param showData 广告对象 /// @param showData 广告对象
/// @param adType 广告类型 /// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{ - (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏 if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频 }else if (adType == ADType_Video){ //视频
if (self.rewardVideoAd.isAdValid) { if (self.rewardVideoAd.isAdValid) {
[self.rewardVideoAd showAdFromRootViewController:self.currentVC]; [self.rewardVideoAd showAdFromRootViewController:self.currentVC];
}else{ }else{
self.showSuccessCallbackBlock(showData, NO); self.showSuccessCallbackBlock(showData, NO);
}
}else if (adType == ADType_BigImage){ //大图
} }
}else if (adType == ADType_BigImage){ //大图 });
}
} }
//MARK:开屏 //MARK:开屏
......
...@@ -62,15 +62,19 @@ ...@@ -62,15 +62,19 @@
/// @param adType 广告类型 /// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{ - (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
if (adType == ADType_OpenScreen) { // 开屏 dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频
}else if (adType == ADType_Video){ //视频
[self.vlnVideoAD showAdFromRootViewController:self.currentVC];
[self.vlnVideoAD showAdFromRootViewController:self.currentVC];
}else if (adType == ADType_BigImage){ //大图
}else if (adType == ADType_BigImage){ //大图
}
}
});
} }
......
...@@ -57,20 +57,22 @@ ...@@ -57,20 +57,22 @@
/// @param showData 广告对象 /// @param showData 广告对象
/// @param adType 广告类型 /// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{ - (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
NSString * ADID = showData.codeId;
dispatch_async(dispatch_get_main_queue(), ^{
NSString * ADID = showData.codeId;
if (adType == ADType_OpenScreen) { // 开屏 if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频 }else if (adType == ADType_Video){ //视频
if ([[WindRewardedVideoAd sharedInstance] isReady:ADID]) { if ([[WindRewardedVideoAd sharedInstance] isReady:ADID]) {
[[WindRewardedVideoAd sharedInstance] playAd:self.currentVC withPlacementId:ADID options:@{} error:nil]; [[WindRewardedVideoAd sharedInstance] playAd:self.currentVC withPlacementId:ADID options:@{} error:nil];
}else{ }else{
self.showSuccessCallbackBlock(showData, NO); self.showSuccessCallbackBlock(showData, NO);
}
}else if (adType == ADType_BigImage){ //大图
} }
}else if (adType == ADType_BigImage){ //大图 });
}
} }
//MARK: ---- 开屏 ---- //MARK: ---- 开屏 ----
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment