FqIronsourceVideo.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // FqIronsourceVideo.m
  3. // QQQ
  4. //
  5. // Created by Mgs on 2020/12/7.
  6. //
  7. #import "FqIronsourceVideo.h"
  8. #import "XSNetwork.h"
  9. @interface FqIronsourceVideo()<ISRewardedVideoDelegate>
  10. @property(nonatomic,assign)BOOL isVideoReadly;
  11. @property(nonatomic,assign)BOOL giveReward;
  12. @property(nonatomic,strong)void(^videoCallback)(BOOL);
  13. @end
  14. @implementation FqIronsourceVideo
  15. -(instancetype)init{
  16. if (self = [super init]) {
  17. self.agentName = @"IronSource"; //平台名称
  18. NSDictionary *infos = [[NSBundle mainBundle] infoDictionary];
  19. self.adUnitId = [infos objectForKey:@"ironsource-video-unitId"];
  20. self.type = @"Rewarded"; //广告类型
  21. self.unitAdId = @""; //广告组ID
  22. [IronSource setRewardedVideoDelegate:self];
  23. self.isVideoReadly = false;
  24. self.giveReward = false;
  25. }
  26. return self;
  27. }
  28. -(BOOL)isAdReady{
  29. return [IronSource hasRewardedVideo];
  30. }
  31. -(void)openVideo:(NSString *)adName callback:(void (^)(BOOL))callback{
  32. self.adId = adName;
  33. self.videoCallback = callback;
  34. dispatch_async(dispatch_get_main_queue(), ^{
  35. UIViewController *vc = [GMTools getViewControl];
  36. [IronSource showRewardedVideoWithViewController:vc placement:adName];
  37. });
  38. //数据上报
  39. [XSNetwork adRecord:@"quest" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  40. }
  41. - (void)rewardedVideoHasChangedAvailability:(BOOL)available{
  42. self.isVideoReadly = available;
  43. }
  44. - (void)didReceiveRewardForPlacement:(ISPlacementInfo *)placementInfo{
  45. self.giveReward = true;
  46. }
  47. - (void)rewardedVideoDidFailToShowWithError:(NSError *)error{
  48. //收集错误日志上报服务器.
  49. self.errorMsg = [NSString stringWithFormat:@"code=%ld,domain=%@,describe=%@",(long)error.code,error.domain,error.userInfo];
  50. if (self.videoCallback) {
  51. self.giveReward = false;
  52. self.videoCallback(self.giveReward);
  53. }
  54. }
  55. - (void)rewardedVideoDidOpen{
  56. [XSNetwork adRecord:@"show" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  57. }
  58. - (void)rewardedVideoDidClose{
  59. [XSNetwork adRecord:@"close" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  60. if (self.videoCallback) {
  61. self.videoCallback(self.giveReward);
  62. self.giveReward = false;
  63. }
  64. }
  65. - (void)rewardedVideoDidStart{
  66. }
  67. - (void)rewardedVideoDidEnd{
  68. }
  69. - (void)didClickRewardedVideo:(ISPlacementInfo *)placementInfo{
  70. [XSNetwork adRecord:@"click" spaceId:self.adId agentName:self.agentName medium:self.medium adUnitId:self.adUnitId type:self.type unitAdId:self.unitAdId errorMsg:self.errorMsg];
  71. }
  72. @end