RxAdMob is a RxSwift wrapper for GoogleAdMob.
// info.plist
<key>GADApplicationIdentifier</key>
<string>YOUR-API-KEY</string>
GADMobileAds.sharedInstance().start()
let interstitial = GADInterstitial(adUnitID: "Your UID")
interstitial.load(GADRequest())
interstitial.rx.isReady
.asDriver(onErrorJustReturn: false)
.filter { $0 }
.drive(onNext: { _ in
interstitial.present(fromRootViewController: self)
})
.disposeBag(by: disposeBag)
// func interstitialWillDismissScreen(_ ad: GADInterstitial)
interstitial.rx.interstitialDidDismissScreen
.asDriver()
.drive(onNext: { interstitial in
interstitial.load(GADRequest())
})
.disposed(by: disposeBag)
// interstitial(_ ad: GADInterstitial, didFailToReceiveAdWithError error: GADRequestError)
interstitial.rx.didFailToReceiveAdWithError
.asDriver()
.drive(onNext: { interstitial, error in
print("Interstitial did fail to receive error: \(error.description)")
})
.disposed(by: disposeBag)
Add to Podfile
:
pod 'RxAdMob'
Than run pod install
public typealias AdLoaderWithError = (adLoader: GADAdLoader, error: Error)
public typealias AdLoaderWithNativeAd = (adLoader: GADAdLoader, nativeAd: GADUnifiedNativeAd)
// Observing Properties
public var adUnitID: Observable<String>
public var isLoading: Observable<Bool>
// Delegate Events
public var adLoaderDidFailToReceiveAdWithError: RxCocoa.ControlEvent<AdLoaderWithError>
public var adLoaderDidReceiveUnifiedNativeAd: RxCocoa.ControlEvent<AdLoaderWithNativeAd>
public var adLoaderDidFinishLoading: RxCocoa.ControlEvent<GADAdLoader>
// Observing Properties
public var type: Observable<String>
public var amount: Observable<NSDecimalNumber>
public typealias BannerViewWithError = (bannerView: GADBannerView, error: Error)
// Observing Properties
public var adUnitID: Observable<String?>
public var rootViewController: Observable<UIViewController?>
public var adSize: Observable<GADAdSize>
public var adNetworkClassName: Observable<String?>
public var adViewDidReceiveAd: ControlEvent<GADBannerView>
// Delegate Events
public var didFailToReceiveAdWithError: ControlEvent<BannerViewWithError>
public var adViewWillPresentScreen: ControlEvent<GADBannerView>
public var adViewWillDismissScreen: ControlEvent<GADBannerView>
public var adViewDidDismissScreen: ControlEvent<GADBannerView>
public var adViewWillLeaveApplication: ControlEvent<GADBannerView>
public typealias InterstitialWithError = (interstitial: GADInterstitial, error: Error)
// Observing Properties
public var adUnitID: Observable<String?>
public var isReady: Observable<Bool>
public var hasBeenUsed: Observable<Bool>
public var adNetworkClassName: Observable<String?>
// Delegate Events
public var interstitialDidReceiveAd: ControlEvent<GADInterstitial>
public var didFailToReceiveAdWithError: ControlEvent<InterstitialWithError>
public var interstitialWillPresentScreen: ControlEvent<GADInterstitial>
public var interstitialWillDismissScreen: ControlEvent<GADInterstitial>
public var interstitialDidDismissScreen: ControlEvent<GADInterstitial>
public var interstitialWillLeaveApplication: ControlEvent<GADInterstitial>
public typealias RewardBasedVideoAdWithReward = (rewardBasedVideoAd: GADRewardBasedVideoAd, reward: GADAdReward)
public typealias RewardBasedVideoAdWithError = (rewardBasedVideoAd: GADRewardBasedVideoAd, error: Error)
// Observing Properties
public var isReady: Observable<Bool>
public var adNetworkClassName: Observable<String?>
public var userIdentifier: Observable<String?>
// Delegate Events
public var didRewardUser: ControlEvent<RewardBasedVideoAdWithReward>
public var rewardBasedVideoAdDidReceive: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidOpen: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidStartPlaying: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidCompletePlaying: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidClose: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdWillLeaveApplication: ControlEvent<GADRewardBasedVideoAd>
public var didFailToLoadWithError: ControlEvent<RewardBasedVideoAdWithError>
public typealias RewardBasedVideoAdWithReward = (rewardBasedVideoAd: GADRewardBasedVideoAd, reward: GADAdReward)
public typealias RewardBasedVideoAdWithError = (rewardBasedVideoAd: GADRewardBasedVideoAd, error: Error)
// Observing Properties
public var isReady: Observable<Bool>
public var adNetworkClassName: Observable<String?>
public var userIdentifier: Observable<String?>
// Delegate Events
public var didRewardUser: ControlEvent<RewardBasedVideoAdWithReward>
public var rewardBasedVideoAdDidReceive: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidOpen: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidStartPlaying: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidCompletePlaying: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdDidClose: ControlEvent<GADRewardBasedVideoAd>
public var rewardBasedVideoAdWillLeaveApplication: ControlEvent<GADRewardBasedVideoAd>
public var didFailToLoadWithError: ControlEvent<RewardBasedVideoAdWithError>
// Observing Properties
public var nativeAd: Observable<GADUnifiedNativeAd?>
public var headlineView: Observable<UIView?>
public var callToActionView: Observable<UIView?>
public var iconView: Observable<UIView?>
public var bodyView: Observable<UIView?>
public var storeView: Observable<UIView?>
public var priceView: Observable<UIView?>
public var imageView: Observable<UIView?>
public var starRatingView: Observable<UIView?>
public var advertiserView: Observable<UIView?>
public var mediaView: Observable<GADMediaView?>
public var adChoicesView: Observable<GADAdChoicesView?>
MIT License