Commit 93c765ca authored by zhangshuai's avatar zhangshuai

优化 广告bug

parent f19e326b
......@@ -357,6 +357,7 @@ static CGNetworkTools* _tools = nil;
if ([[data Read] objectForKey:@"source"]) {
[dict setValue: [[data Read] objectForKey:@"source"] forKey: @"source"];
}
[dict setValue: @"toutiao" forKey: @"source"];
NSString *uid = [[data Read] objectForKey:@"uid"];
if (uid != nil) { [dict setValue: uid forKey: @"uid"]; }
......
......@@ -213,9 +213,11 @@ static IOSADManager * manager = nil;
/// @param loadADModel 广告对象
/// @param AdType 广告类型
- (void)loadAdWithData:(GYAdsTrackModel *)loadADModel withADType:(eADType )AdType;{
NSLog(@">>>>>>> 准备缓存 平台 = %@ ID = %@ type= %@ <<<<<<<<<",loadADModel.adPlatform,loadADModel.codeId,loadADModel.slotName);
self.haveLodeAD = YES;
loadADModel.loadADType = AdType;
if ([self.loadADDataArray count] > 6) {
if ([self.loadADDataArray count] > 10) {
[self.loadADDataArray removeObject:self.loadADDataArray.firstObject];
}
WEAKSELF;
......@@ -231,11 +233,10 @@ static IOSADManager * manager = nil;
time = 5;
}
// 去加载
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.csjAd = nil;
weakSelf.csjAd = nil;
AddCSJADManager * csjAd = [[AddCSJADManager alloc]init];
self.csjAd = csjAd;
[self.loadADDataArray addObject:csjAd];
weakSelf.csjAd = csjAd;
[weakSelf.loadADDataArray addObject:csjAd];
[csjAd loadAdWithData:loadADModel withADType:AdType];
......@@ -245,6 +246,8 @@ static IOSADManager * manager = nil;
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(), ^{
});
}
......@@ -312,8 +315,8 @@ static IOSADManager * manager = nil;
}
}else{
if (AdType == ADType_Video) { // 视频
GYAdsTrackModel * adData = loadADModel;
if (self.videoModels.count > self.cachevideo.count) {
GYAdsTrackModel * adData = self.videoModels[self.cachevideo.count];
NSLog(@">>>>>>> 缓存 失败 %@ 不支持",adData.adPlatform);
if (adData.firstFailure == NO) {
......@@ -332,6 +335,10 @@ static IOSADManager * manager = nil;
[self requestVideoAD];
}
}
}else{
[self requestVideoAD];
}
}else if (AdType == ADType_OpenScreen){
......@@ -375,27 +382,26 @@ static IOSADManager * manager = nil;
/// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
if (adType == ADType_Video) { // 视频
NSLog(@">>>>>>> 正在播放 成功 平台 = %@ ID = %@ <<<<<<<<<",showData.adPlatform,showData.codeId);
NSLog(@">>>>>>> 正在播放 成功 平台 = %@ ID = %@ type =%@ <<<<<<<<<",showData.adPlatform,showData.codeId,showData.slotName);
WEAKSELF;
dispatch_async(dispatch_get_main_queue(), ^{
if ([showData.adPlatform isEqualToString:@"chuanshanjia"]) {
[self.csjAd showAdWithData:showData withADType:adType];
[weakSelf.csjAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"guangdiantong"]){
[self.gdtAd showAdWithData:showData withADType:adType];
[weakSelf.gdtAd showAdWithData:showData withADType:adType];
}else if ([showData.adPlatform isEqualToString:@"sigmob"]){
[self.sigmobAd showAdWithData:showData withADType:adType];
[weakSelf.sigmobAd showAdWithData:showData withADType:adType];
}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{
[self loadAdWithData:self.videoModels[1] withADType:ADType_Video];
[weakSelf loadAdWithData:weakSelf.videoModels[1] withADType:ADType_Video];
}
}else if (adType == ADType_BigImage){ //大图
......@@ -423,8 +429,9 @@ static IOSADManager * manager = nil;
- (void)requestOpenScreenAD;{
WEAKSELF;
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"splash"} success:^(id _Nonnull response) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) {
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_success"];
NSMutableArray * models = [NSMutableArray new];
......@@ -452,8 +459,9 @@ static IOSADManager * manager = nil;
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"];
}
} failure:^(NSError * _Nonnull error) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
[[CGUserManager shared] addLocCollection:@"splash_request" value:@"splash_request_failed"];
}];
}
......@@ -461,8 +469,9 @@ static IOSADManager * manager = nil;
- (void)requestNativeAD;{
WEAKSELF;
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_bigimage"} success:^(id _Nonnull response) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) {
[[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_success"];
......@@ -490,8 +499,9 @@ static IOSADManager * manager = nil;
}
} failure:^(NSError * _Nonnull error) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
[[CGUserManager shared] addLocCollection:@"native_request" value:@"native_request_failed"];
}];
......@@ -510,8 +520,9 @@ static IOSADManager * manager = nil;
}
[[CGNetworkTools shared] getWithAdsAction:getAdsInfo parameters: @{@"slotName": @"common_video"} success:^(id _Nonnull response) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if ([[response objectForKey:@"status"] intValue] == 200) {
requestToTry = 0;
......@@ -551,12 +562,14 @@ static IOSADManager * manager = nil;
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"];
}
} failure:^(NSError * _Nonnull error) {
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
requestToTry += 1;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf requestVideoAD];
});
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [weakSelf requestVideoAD];
// });
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_request_failed"];
}];
......@@ -576,21 +589,56 @@ static IOSADManager * manager = nil;
NSLog(@">>>>>>> 缓存 失败 平台 = %@ ID = %@ type= %@ <<<<<<<<<",model.adPlatform,model.codeId,model.slotName);
}
if(model.loadADType == ADType_Video){
weakSelf.haveLodeAD = NO;
dispatch_async(dispatch_get_main_queue(), ^{
[MBProgressHUD hideHUD];
});
if (success) {
[[CGUserManager shared] addLocCollection:@"reward_request" value:@"reward_back_success"];
[weakSelf.cachevideo addObject:model];
if(weakSelf.showNow){
[weakSelf showADType:ADType_Video resultBlock:self.adShowBlock];
[weakSelf showADType:ADType_Video resultBlock:weakSelf.adShowBlock];
}
}else{
if (weakSelf.videoModels.count > weakSelf.cachevideo.count) {
GYAdsTrackModel * firstData = weakSelf.videoModels[weakSelf.cachevideo.count];
[[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){
......
......@@ -72,6 +72,7 @@
/// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频
......@@ -83,6 +84,9 @@
}else if (adType == ADType_BigImage){ //大图
}
});
}
......
......@@ -66,7 +66,7 @@
/// @param showData 广告对象
/// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频
......@@ -78,6 +78,8 @@
}else if (adType == ADType_BigImage){ //大图
}
});
}
//MARK:开屏
......
......@@ -62,6 +62,7 @@
/// @param adType 广告类型
- (void)showAdWithData:(GYAdsTrackModel *)showData withADType:(eADType)adType;{
dispatch_async(dispatch_get_main_queue(), ^{
if (adType == ADType_OpenScreen) { // 开屏
}else if (adType == ADType_Video){ //视频
......@@ -71,6 +72,9 @@
}else if (adType == ADType_BigImage){ //大图
}
});
}
......
......@@ -57,9 +57,9 @@
/// @param showData 广告对象
/// @param 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) { // 开屏
}else if (adType == ADType_Video){ //视频
......@@ -71,6 +71,8 @@
}else if (adType == ADType_BigImage){ //大图
}
});
}
//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