| | |
| | | |
| | | //广点通原生广告的头文件 |
| | | #import "ADCollectionReusableView.h" |
| | | #import "GDTNativeAd.h" |
| | | //#import "GDTNativeAd.h" |
| | | #import "GDTNativeExpressAd.h" |
| | | #import "GDTNativeExpressAdView.h" |
| | | #import "FaxianCReusableView.h" |
| | | |
| | | @interface searchViewController ()<YTHSearchTextFieldDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,GDTNativeAdDelegate>{ |
| | | @interface searchViewController ()<YTHSearchTextFieldDelegate,UITableViewDataSource,UITableViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate,GDTNativeExpressAdDelegete>{ |
| | | //广点通原生广告 |
| | | GDTNativeAd *_nativeAd; //原生广告实例 |
| | | NSMutableArray *nativeArray;//存储请求下来的原生广告信息 |
| | | // GDTNativeAd *_nativeAd; //原生广告实例 |
| | | // NSMutableArray *nativeArray;//存储请求下来的原生广告信息 |
| | | } |
| | | @property (nonatomic , strong) UICollectionView *collectionView; |
| | | |
| | |
| | | @property (nonatomic , strong) NSMutableArray *dataOld;//历史搜索 |
| | | |
| | | @property (nonatomic , strong) NSMutableArray *historySearchArray;//存放历史搜索记录的数组 |
| | | |
| | | @property (nonatomic, strong) NSArray *expressAdViews; |
| | | @property (nonatomic, strong) GDTNativeExpressAd *nativeExpressAd; |
| | | @end |
| | | |
| | | @implementation searchViewController |
| | |
| | | [self.collectionView registerNib:[UINib nibWithNibName:@"SearchCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SearchCollectionReusableViewID"]; |
| | | //设置尾部芒果广告的foot |
| | | [self.collectionView registerNib:[UINib nibWithNibName:@"ADCollectionReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView"]; |
| | | [self.collectionView registerNib:[UINib nibWithNibName:@"FaxianCReusableView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FaxianCReusableView"]; |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | |
| | | -(void)clickADs{ |
| | | GDTNativeAdData * info =nativeArray[0]; |
| | | [_nativeAd clickAd:info]; |
| | | // GDTNativeAdData * info =nativeArray[0]; |
| | | // [_nativeAd clickAd:info]; |
| | | } |
| | | |
| | | |
| | |
| | | * 加载广点通原生广告 |
| | | */ |
| | | -(void)loadAd{ |
| | | _nativeAd = [[GDTNativeAd alloc] initWithAppkey:GDTADkey placementId:GDTYSADkey3]; |
| | | _nativeAd.controller = self; |
| | | _nativeAd.delegate = self; |
| | | [_nativeAd loadAd:1]; |
| | | // _nativeAd = [[GDTNativeAd alloc] initWithAppkey:GDTADkey placementId:GDTYSADkey3]; |
| | | // _nativeAd.controller = self; |
| | | // _nativeAd.delegate = self; |
| | | // [_nativeAd loadAd:1]; |
| | | // 支持视频广告的 PlacementId 会混出视频与图片广告 |
| | | self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithAppId:GDTADkey placementId:GDTYSADkey3 adSize:CGSizeMake(KScreenW, (KScreenW-20)/16*9 + 10)]; |
| | | self.nativeExpressAd.delegate = self; |
| | | // 配置视频播放属性 |
| | | self.nativeExpressAd.videoAutoPlayOnWWAN = YES; |
| | | self.nativeExpressAd.videoMuted = NO; |
| | | [self.nativeExpressAd loadAd:10]; |
| | | } |
| | | |
| | | - (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd |
| | | *)nativeExpressAd views:(NSArray<__kindof |
| | | GDTNativeExpressAdView *> *)views |
| | | { |
| | | self.expressAdViews = [NSArray arrayWithArray:views]; |
| | | if (self.expressAdViews.count) { |
| | | [self.expressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { |
| | | GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj; |
| | | expressView.controller = self; |
| | | [expressView render]; |
| | | }]; |
| | | } |
| | | // 广告位 render 后刷新 tableView |
| | | [_collectionView reloadData]; |
| | | } |
| | | - (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error{ |
| | | NSLog(@"%@",error); |
| | | } |
| | | |
| | | /** |
| | | * 清除历史记录 |
| | |
| | | /** |
| | | * 原生广告加载广告数据成功回调,返回为GDTNativeAdData对象的数组 |
| | | */ |
| | | -(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{ |
| | | if (!nativeArray) { |
| | | nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray]; |
| | | }else{ |
| | | [nativeArray addObjectsFromArray:nativeAdDataArray]; |
| | | } |
| | | [_collectionView reloadData]; |
| | | } |
| | | //-(void)nativeAdSuccessToLoad:(NSArray *)nativeAdDataArray{ |
| | | // if (!nativeArray) { |
| | | // nativeArray =[[NSMutableArray alloc]initWithArray:nativeAdDataArray]; |
| | | // }else{ |
| | | // [nativeArray addObjectsFromArray:nativeAdDataArray]; |
| | | // } |
| | | // [_collectionView reloadData]; |
| | | //} |
| | | |
| | | /** |
| | | * 原生广告加载广告数据失败回调 |
| | | */ |
| | | -(void)nativeAdFailToLoad:(NSError *)error{ |
| | | NSLog(@"XYR_%@",error); |
| | | } |
| | | //-(void)nativeAdFailToLoad:(NSError *)error{ |
| | | // NSLog(@"XYR_%@",error); |
| | | //} |
| | | |
| | | #pragma mark -YTHSearchTextFieldDelegate |
| | | - (void)YTHSearchField:(YTHSearchTextField *)searchField SearchValueChanged:(UITextField *)textField{//实时监控 |
| | |
| | | if (indexPath.section==1) { |
| | | //返回广告视图 |
| | | ADCollectionReusableView *groupfootSection = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ADCollectionReusableView" forIndexPath:indexPath]; |
| | | GDTNativeAdData *info=nativeArray[0]; |
| | | |
| | | groupfootSection.ADTitle.text=[info.properties objectForKey:GDTNativeAdDataKeyTitle]; |
| | | groupfootSection.ADTitle.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7]; |
| | | [groupfootSection.ADImage setYthImageWithURL:[info.properties objectForKey:GDTNativeAdDataKeyImgUrl] placeholderImage:[UIImage imageNamed:@"默认加载图片"]]; |
| | | //把button设为透明 |
| | | groupfootSection.ADClickButton.backgroundColor=[UIColor clearColor]; |
| | | [groupfootSection.ADClickButton addTarget:self action:@selector(clickADs) forControlEvents:UIControlEventTouchUpInside]; |
| | | [_nativeAd attachAd:info toView:groupfootSection]; |
| | | // GDTNativeAdData *info=nativeArray[0]; |
| | | // |
| | | // groupfootSection.ADTitle.text=[info.properties objectForKey:GDTNativeAdDataKeyTitle]; |
| | | // groupfootSection.ADTitle.backgroundColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7]; |
| | | // [groupfootSection.ADImage setYthImageWithURL:[info.properties objectForKey:GDTNativeAdDataKeyImgUrl] placeholderImage:[UIImage imageNamed:@"默认加载图片"]]; |
| | | // //把button设为透明 |
| | | // groupfootSection.ADClickButton.backgroundColor=[UIColor clearColor]; |
| | | // [groupfootSection.ADClickButton addTarget:self action:@selector(clickADs) forControlEvents:UIControlEventTouchUpInside]; |
| | | // [_nativeAd attachAd:info toView:groupfootSection]; |
| | | GDTNativeExpressAdView *adView = (GDTNativeExpressAdView *)self.expressAdViews[0]; |
| | | // FaxianCReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"FaxianCReusableView" forIndexPath:indexPath]; |
| | | // [view addSubview:groupfootSection]; |
| | | [groupfootSection addSubview:adView]; |
| | | return groupfootSection; |
| | | // return view; |
| | | |
| | | } |
| | | } |
| | | return nil; |
| | |
| | | |
| | | - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{ |
| | | if(section==1){ |
| | | if (nativeArray==nil) { |
| | | if (self.expressAdViews==nil) { |
| | | return CGSizeMake(0, 0); |
| | | }else{ |
| | | return CGSizeMake(0, KScreenW/2+15); |
| | | UIView *view = self.expressAdViews[0]; |
| | | |
| | | return CGSizeMake(0, view.bounds.size.height); |
| | | } |
| | | }else{ |
| | | return CGSizeMake(0, 0); |