ALMediationAdapterRouter.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // ALMediationAdapterRouter.h
  3. // AppLovinSDK
  4. //
  5. // Created by Christopher Cong on 10/25/18.
  6. //
  7. #import <UIKit/UIKit.h>
  8. #import <AppLovinSDK/MAAdapter.h>
  9. #import <AppLovinSDK/MAAdViewAdapterDelegate.h>
  10. #import <AppLovinSDK/MAAppOpenAdapterDelegate.h>
  11. #import <AppLovinSDK/MAInterstitialAdapterDelegate.h>
  12. #import <AppLovinSDK/MARewardedAdapterDelegate.h>
  13. @class MAAdapterError;
  14. @class MAReward;
  15. NS_ASSUME_NONNULL_BEGIN
  16. /**
  17. * For ad networks with a singleton callback pattern, this class is responsible for routing their events to our mediation adapters.
  18. *
  19. * This class should only be initialized once per adapter and must be subclassed to be used. Use -sharedInstance to create and access a router.
  20. * Subclasses should map an ad network's ad events to the methods marked under Ad Network Event Router.
  21. **/
  22. @interface ALMediationAdapterRouter : NSObject
  23. /**
  24. * For ad networks whose initialization is completed asynchronously, the router will need to retain the completionHandler until the initialization is completed.
  25. * Be sure to set this to nil after calling it.
  26. */
  27. //TODO: remove this once adapter routers have moved away from initialization.
  28. @property (nonatomic, copy, nullable) void(^completionHandler)(void);
  29. /**
  30. * Mediation adapters should call this when loading an interstitial ad.
  31. *
  32. * @param adapter Mediation adapter responsible for the mediated ad request.
  33. * @param delegate Delegate that is listening to the mediation adapter events.
  34. * @param placementIdentifier Placement identifier requested for the ad load.
  35. */
  36. - (void)addInterstitialAdapter:(id<MAAdapter>)adapter
  37. delegate:(id<MAInterstitialAdapterDelegate>)delegate
  38. forPlacementIdentifier:(NSString *)placementIdentifier;
  39. /**
  40. * Mediation adapters should call this when loading an app open ad.
  41. *
  42. * @param adapter Mediation adapter responsible for the mediated ad request.
  43. * @param delegate Delegate that is listening to the mediation adapter events.
  44. * @param placementIdentifier Placement identifier requested for the ad load.
  45. */
  46. - (void)addAppOpenAdapter:(id<MAAdapter>)adapter
  47. delegate:(id<MAAppOpenAdapterDelegate>)delegate
  48. forPlacementIdentifier:(NSString *)placementIdentifier;
  49. /**
  50. * Mediation adapters should call this when loading a rewarded ad.
  51. *
  52. * @param adapter Mediation adapter responsible for the mediated ad request.
  53. * @param delegate Delegate that is listening to the mediation adapter events.
  54. * @param placementIdentifier Placement identifier requested for the ad load.
  55. */
  56. - (void)addRewardedAdapter:(id<MAAdapter>)adapter
  57. delegate:(id<MARewardedAdapterDelegate>)delegate
  58. forPlacementIdentifier:(NSString *)placementIdentifier;
  59. /**
  60. * Mediation adapters should call this when loading an ad view.
  61. *
  62. * @param adapter Mediation adapter responsible for the mediated ad request.
  63. * @param delegate Delegate that is listening to the mediation adapter events.
  64. * @param placementIdentifier Placement identifier requested for the ad load.
  65. * @param adView The ad view for the adapter. May be null.
  66. */
  67. - (void)addAdViewAdapter:(id<MAAdapter>)adapter
  68. delegate:(id<MAAdViewAdapterDelegate>)delegate
  69. forPlacementIdentifier:(NSString *)placementIdentifier
  70. adView:(nullable UIView *)adView;
  71. /**
  72. * Updates the underlying ad view for the given placement id. This is useful if by the time an adapter is added
  73. * to the router's map, there is no ad view present yet. (e.g. UnityAds).
  74. *
  75. * @param adView The ad view to update for the adapter.
  76. * @param placementIdentifier Placement identifier for the ad view.
  77. */
  78. - (void)updateAdView:(UIView *)adView forPlacementIdentifier:(NSString *)placementIdentifier;
  79. /**
  80. * Mediation should call this on when showing an ad.
  81. */
  82. - (void)addShowingAdapter:(id<MAAdapter>)showingAdapter;
  83. /**
  84. * Mediation adapters should call this on -destroy.
  85. */
  86. - (void)removeAdapter:(id<MAAdapter>)adapter forPlacementIdentifier:(NSString *)placementIdentifier;
  87. #pragma mark - Ad Network Event Router
  88. - (void)didLoadAdForPlacementIdentifier:(NSString *)placementIdentifier;
  89. - (void)didLoadAdForPlacementIdentifier:(NSString *)placementIdentifier withExtraInfo:(nullable NSDictionary<NSString *, id> *)extraInfo;
  90. - (void)didFailToLoadAdForPlacementIdentifier:(NSString *)placementIdentifier error:(MAAdapterError *)error;
  91. - (void)didDisplayAdForPlacementIdentifier:(NSString *)placementIdentifier;
  92. - (void)didDisplayAdForPlacementIdentifier:(NSString *)placementIdentifier withExtraInfo:(nullable NSDictionary<NSString *, id> *)extraInfo;
  93. - (void)didFailToDisplayAdForPlacementIdentifier:(NSString *)placementIdentifier error:(MAAdapterError *)error;
  94. - (void)didClickAdForPlacementIdentifier:(NSString *)placementIdentifier;
  95. - (void)didHideAdForPlacementIdentifier:(NSString *)placementIdentifier;
  96. // Rewarded delegate methods
  97. - (void)didStartRewardedVideoForPlacementIdentifier:(NSString *)placementIdentifier
  98. __deprecated_msg("This API is deprecated because not all adapters support this callback. Please use -[ALMediationAdapterRouter didDisplayAdForPlacementIdentifier:] instead");
  99. - (void)didCompleteRewardedVideoForPlacementIdentifier:(NSString *)placementIdentifier
  100. __deprecated_msg("This API is deprecated because not all adapters support this callback. Please use -[ALMediationAdapterRouter didHideAdForPlacementIdentifier:] instead");
  101. - (void)didRewardUserForPlacementIdentifier:(NSString *)placementIdentifier withReward:(MAReward *)reward;
  102. // AdView delegate methods
  103. - (void)didExpandAdForPlacementIdentifier:(NSString *)placementIdentifier;
  104. - (void)didCollapseAdForPlacementIdentifier:(NSString *)placementIdentifier;
  105. #pragma mark - Adapter Reward Utility Methods
  106. - (MAReward *)rewardForPlacementIdentifier:(NSString *)placementIdentifier;
  107. - (BOOL)shouldAlwaysRewardUserForPlacementIdentifier:(NSString *)placementIdentifier;
  108. #pragma mark - Logging Methods
  109. - (void)log:(NSString *)format, ...;
  110. - (void)log:(NSString *)message becauseOf:(NSException *)exception;
  111. #pragma mark - Singleton
  112. /**
  113. * This implementation uses the Registry Pattern to create/return the shared instance for a given subclass caller.
  114. */
  115. + (instancetype)sharedInstance;
  116. @end
  117. NS_ASSUME_NONNULL_END