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,11 +233,10 @@ static IOSADManager * manager = nil; ...@@ -231,11 +233,10 @@ static IOSADManager * manager = nil;
time = 5; time = 5;
} }
// 去加载 // 去加载
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ weakSelf.csjAd = nil;
self.csjAd = nil;
AddCSJADManager * csjAd = [[AddCSJADManager alloc]init]; AddCSJADManager * csjAd = [[AddCSJADManager alloc]init];
self.csjAd = csjAd; weakSelf.csjAd = csjAd;
[self.loadADDataArray addObject:csjAd]; [weakSelf.loadADDataArray addObject:csjAd];
[csjAd loadAdWithData:loadADModel withADType:AdType]; [csjAd loadAdWithData:loadADModel withADType:AdType];
...@@ -245,6 +246,8 @@ static IOSADManager * manager = nil; ...@@ -245,6 +246,8 @@ static IOSADManager * manager = nil;
csjAd.showSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) { csjAd.showSuccessCallbackBlock = ^(GYAdsTrackModel * _Nonnull model, BOOL success) {
[weakSelf blockResultShowWithData:model andSuccess:YES]; [weakSelf blockResultShowWithData:model andSuccess:YES];
}; };
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
}); });
} }
...@@ -312,8 +315,8 @@ static IOSADManager * manager = nil; ...@@ -312,8 +315,8 @@ 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); NSLog(@">>>>>>> 缓存 失败 %@ 不支持",adData.adPlatform);
if (adData.firstFailure == NO) { if (adData.firstFailure == NO) {
...@@ -332,6 +335,10 @@ static IOSADManager * manager = nil; ...@@ -332,6 +335,10 @@ static IOSADManager * manager = nil;
[self requestVideoAD]; [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;
dispatch_async(dispatch_get_main_queue(), ^{
if ([showData.adPlatform isEqualToString:@"chuanshanjia"]) { if ([showData.adPlatform isEqualToString:@"chuanshanjia"]) {
[self.csjAd showAdWithData:showData withADType:adType]; [weakSelf.csjAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"guangdiantong"]){ }else if ([showData.adPlatform isEqualToString:@"guangdiantong"]){
[self.gdtAd showAdWithData:showData withADType:adType]; [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) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf requestVideoAD];
}); });
if (weakSelf.videoModels.count <= 1) {
[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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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"];
}]; }];
...@@ -576,21 +589,56 @@ static IOSADManager * manager = nil; ...@@ -576,21 +589,56 @@ static IOSADManager * manager = nil;
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;
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD]; [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{
if (weakSelf.videoModels.count > weakSelf.cachevideo.count) {
GYAdsTrackModel * firstData = weakSelf.videoModels[weakSelf.cachevideo.count];
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_failed"]; [[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_failed"];
[weakSelf clearCache:model];
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){
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
/// @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){ //视频
...@@ -83,6 +84,9 @@ ...@@ -83,6 +84,9 @@
}else if (adType == ADType_BigImage){ //大图 }else if (adType == ADType_BigImage){ //大图
} }
});
} }
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
/// @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){ //视频
...@@ -78,6 +78,8 @@ ...@@ -78,6 +78,8 @@
}else if (adType == ADType_BigImage){ //大图 }else if (adType == ADType_BigImage){ //大图
} }
});
} }
//MARK:开屏 //MARK:开屏
......
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
/// @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){ //视频
...@@ -71,6 +72,9 @@ ...@@ -71,6 +72,9 @@
}else if (adType == ADType_BigImage){ //大图 }else if (adType == ADType_BigImage){ //大图
} }
});
} }
......
...@@ -57,9 +57,9 @@ ...@@ -57,9 +57,9 @@
/// @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){ //视频
...@@ -71,6 +71,8 @@ ...@@ -71,6 +71,8 @@
}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