RQUnDoProjectCell.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //
  2. // RQUnDoProjectCell.m
  3. // NiuBi
  4. //
  5. // Created by 张嵘 on 2023/3/9.
  6. //
  7. #import "RQUnDoProjectCell.h"
  8. #import "GDTNativeExpressAd.h"
  9. #import "GDTNativeExpressAdView.h"
  10. @interface RQUnDoProjectCell () <GDTNativeExpressAdDelegete>
  11. @property (nonatomic, readwrite, strong) RQUnDoProjectItemViewModel *viewModel;
  12. @property (nonatomic, readwrite, strong) NSArray *expressAdViews;
  13. @property (nonatomic, readwrite, strong) GDTNativeExpressAd *nativeExpressAd;
  14. @end
  15. @implementation RQUnDoProjectCell
  16. + (instancetype)cellWithCollectionView:(UICollectionView *)collectionView forIndexPath:(NSIndexPath *)indexPath {
  17. static NSString *ID = @"RQUnDoProjectCell";
  18. [collectionView registerNib:[UINib nibWithNibName:ID bundle:nil] forCellWithReuseIdentifier:ID];
  19. RQUnDoProjectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
  20. if (!cell) cell = [self rq_viewFromXib];
  21. return cell;
  22. }
  23. - (void)bindViewModel:(RQUnDoProjectItemViewModel *)viewModel {
  24. _viewModel = viewModel;
  25. }
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. // 支持视频广告的 PlacementId 会混出视频与图片广告
  29. self.nativeExpressAd = [[GDTNativeExpressAd alloc] initWithPlacementId:@"4085226003670734" adSize:CGSizeMake(RQ_SCREEN_WIDTH - 32.f, (RQ_SCREEN_WIDTH - 32.f) * (3.f / 4.f))];
  30. self.nativeExpressAd.delegate = self;
  31. [self.nativeExpressAd loadAd:1];
  32. }
  33. - (void)nativeExpressAdSuccessToLoad:(GDTNativeExpressAd
  34. *)nativeExpressAd views:(NSArray<__kindof
  35. GDTNativeExpressAdView *> *)views {
  36. @weakify(self)
  37. self.expressAdViews = [NSArray arrayWithArray:views];
  38. if (self.expressAdViews.count) {
  39. [self.expressAdViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  40. @strongify(self)
  41. GDTNativeExpressAdView *expressView = (GDTNativeExpressAdView *)obj;
  42. [self.contentView addSubview:expressView];
  43. expressView.controller = RQControllerHelper.currentViewController;
  44. if ([expressView isAdValid]) {
  45. [expressView render];
  46. }
  47. }];
  48. }
  49. }
  50. - (void)nativeExpressAdFailToLoad:(GDTNativeExpressAd *)nativeExpressAd error:(NSError *)error {
  51. }
  52. @end