How to use GADRewardBasedVideoAd

How to use GADRewardBasedVideoAd

By : Lington Maia
Date : November 21 2020, 11:01 PM
may help you . You have to setup and use third party ad networks for GADRewardBasedVideoAd on AdMob.com.
From Rewarded Video: Publishers Get Started:
code :

Share : facebook icon twitter icon
Tab Controller is dismissing as well when GADRewardBasedVideoAd in AdMob dismisses

Tab Controller is dismissing as well when GADRewardBasedVideoAd in AdMob dismisses

By : user23227
Date : March 29 2020, 07:55 AM
around this issue For those of you who is facing the the same issue:
You can create a new class for your rootViewController (TabBarController or NavigationController etc.) and implement there something like that:
code :
override func dismiss(animated flag: Bool, completion: (() -> Void)? = nil) {
    dismissalCounter += 1
    if (dismissalCounter < 2) {
       super.dismiss(animated: flag, completion: completion)

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
    dismissalCounter = 0

override func present(_ viewControllerToPresent: UIViewController, animated flag: Bool, completion: (() -> Void)? = nil) {
    dismissalCounter = 0
    super.present(viewControllerToPresent, animated: flag, completion: completion)

var dismissalCounter : Int = 0
class ViewController : UIViewController {  
override func viewWillAppear(_ animated: Bool) {
        if GADRewardBasedVideoAd.sharedInstance().isReady == false {
             let request = GADRequest()
            rewardBasedVideo!.load(request, withAdUnitID: "ca-app-pub-3940256099942544/1712485313")

    var rewardBasedVideo: GADRewardBasedVideoAd?

    @IBAction func ad_button_click(_ sender: Any) {
        if rewardBasedVideo!.isReady == true     {
            let bl = blur()
            self.present(bl, animated: true, completion: {
                self.rewardBasedVideo?.present(fromRootViewController: bl)



class blur : UIViewController {
    override func viewDidLoad() {

    func checkForKeyWindow() {
        DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: {
            if (UIApplication.topViewController() == self) {
                print("dismissed and forgotten")
                self.dismiss(animated: true, completion: nil)
            } else {
                print("not keywindow")

    @objc func close() {
       self.dismiss(animated: true, completion: nil)

extension UIApplication {
    class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {

        if let nav = base as? UINavigationController {
            return topViewController(base: nav.visibleViewController)

        if let tab = base as? UITabBarController {
            let moreNavigationController = tab.moreNavigationController

            if let top = moreNavigationController.topViewController, top.view.window != nil {
                return topViewController(base: top)
            } else if let selected = tab.selectedViewController {
                return topViewController(base: selected)

        if let presented = base?.presentedViewController {
            return topViewController(base: presented)

        return base
Related Posts Related Posts :
  • how to manage Height of UITableHeaderView in based on webview content using auto layout
  • viewDidLoad vs ViewWillAppear in IOS
  • Presenting a detail view controller from a map annotation in swift 3?
  • What is industry standard for when to push/pull between core data and remote database
  • Error when moving objects between NSMutableArray
  • Assigning values to class instance from json output
  • Does Facebook SDK support Swift 2.3/3.0?
  • google maps iOS SDK: custom icons to be used as markers
  • Difficulty reading UserDefaults with Fastlane Snapshot
  • Find individual load time of Dynamic Libraries to identify which library consumes more time to load in IOS
  • Can I add local and remote notifications in my iMessage extension?
  • UIImage goes where i tap (But i need it so you can ONLY drag it)
  • How to handle launch options in Swift 3 when a notification is tapped? Getting syntax problems
  • Mismatched colors on UINavigationBar and UISearchBar
  • iOS app that collects data from "Accu-Chek Aviva Connect" BG meter. (Bluetooth Low Energy)
  • How to make a Sprite node spin when a user taps the screen? Swift 3
  • React Native (iOS) app loads nicely on wifi; crashes on LTE/cell
  • Get game request ID / Access Facebook game request notification content
  • Error opening shared document via CloudKit
  • SKPhysicsJointLimit has a elastic behaviour, but i need a strong rope simulation
  • Handing a response in a controller after segueing to another controller
  • Alamofire request gets stuck when entering background?
  • iOS swift: App Transport Security has blocked a cleartext HTTP (http://) resource
  • Full Screen layout for in Xcode 8
  • Provisioning Profile issue after switching to new iPhone in XCode 8
  • how can I center my map on the annotation view only when it is close to the edge of the screen?
  • How can I choose phone number in INSendPaymentIntent
  • Unrecognized selector error trying to use a tap gesture recognizer
  • How to create an image pixel by pixel
  • How can I detect scrolling for update before end dragging event in iOS?
  • GLSL transparency issue only on iOS
  • Tableview simple display value
  • How to display tableview section headers with long text in multiple rows?
  • IOS 10,What's the current syntax for JSQMessagesAvatarImageFactory.avatarImage(Unknow parameters)
  • Passing data with protocols without going back to original controller
  • how do I set a variable to get value from Firebase database structure in Swift
  • Scroll to Table View Header top
  • Custom shape UIButton
  • ImageView of a custom CollectionViewCell is nil when it should be configured
  • Where to set UIRectCorner inside UITableViewCell
  • UINavigationBar frame height returns 44.0 but is actually 64.0
  • Run Xcode 6.x on macOS Sierra 10.12
  • meteor cordova build error for ios platform
  • detailTextLabel doesn't show
  • Navigate to specific TabBar item
  • How to alphabetize an array of objects within Swift 3?
  • swift realm::IncorrectThreadException: Realm accessed from incorrect thread
  • Xcode 8, unable to run the app on device, suddenly there is an error "An invalid key was encountered"
  • inline bool objc_object::isTaggedPointer(); How does the function work?
  • Invalid session toked after deleting a user Parse Server Swift
  • Sharing a file with data in it by UIActivityViewController
  • Firebase Push Notifications
  • Creating a webpage and asyncronously loading app data off of it
  • Use of unresolved identifier 'enumerate' after Swift Migration
  • Max value for each object in an Array of Dictionaries
  • How to set variables from a Firebase snapshot (swift)
  • Xcode 8 template won't generate files
  • objective-c property name: use uppercase character as first character of property name
  • xcassets what are the pixel sizes for Universal x1, x2, x3?
  • Invalid top-level type in JSON write'
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com