MichaelStott / KivMob

AdMob support for Kivy
MIT License
143 stars 38 forks source link

Interstitial ad issue (not working without button) #64

Open solari985 opened 4 years ago

solari985 commented 4 years ago

Hi Michael, I have similar issues what were mentioned before (in issue 5 and 17). My test interstitial ad is shown only after tapping the button 2 times (from test code) and when I try without button, it doesn't appear at all, self.ads.is_interstitial_loaded() = False and nothing happens, also nothing at 2nd time after request and show again. Why this happens? Why the button needed? It is hard to imagine that it is related to the account and the payment, but could be that the case? Thank you in advance.

MichaelStott commented 4 years ago

I don't think it would be an AdMob account issue. I'll take another look. Do you have any example code of your application that you can share?

solari985 commented 4 years ago

Hi, I want the interstitial to be shown after quitting the app, so 1st I call an exit func and stop the app with:

App.get_running_app().stop()

next I perform a reset, because of a similar ERROR discussed here: https://stackoverflow.com/questions/38289017/python-spyder-initializing-hello-world-kivi-app-once and here: https://groups.google.com/forum/m/#!topic/kivy-users/yfhH7skAEJA

after that if I run this code, it works with pushing the button twice:

class InterstitialTest(App):
    """ Display an interstitial ad on button release.
    """

    def build(self):        
        self.ads = KivMob("ca-app-pub- . . . ")        
        self.ads.new_interstitial("ca-app-pub- . . . ")
        self.ads.request_interstitial()
        return Button(text='Show Interstitial',
                      on_release=lambda a:self.ads.show_interstitial())        

    def on_resume(self):
        self.ads.request_interstitial()

and the unsuccessful try without button:

class InterstitialTest(App):
    """ Display an interstitial ad on button release.
    """

    def build(self):
        self.ads = KivMob("ca-app-pub- . . . ")        
        self.ads.new_interstitial("ca-app-pub- . . . ")
        self.ads.request_interstitial()
        if self.ads.is_interstitial_loaded():            
            self.ads.show_interstitial()            
        else:            
            self.ads.request_interstitial()
            self.ads.show_interstitial()

at the end of this I'm not sure if the show is needed or not (unfortunately gives the same result), because when I use the button, at on_resume the show doesn't needed. Thank you for checking this.

akgupta0777 commented 4 years ago

Well I tested this thing out and load an interstitial without even tapping a button. Yes , Interstitial is working without a button.

Just request your interstitial before entering a screen by defining a function on_pre_enter(self,*args) in the screen class, and show the interstitial before leaving the screen by defining on_pre_leave(self) in the screen class.

solari985 commented 4 years ago

@akgupta0777 The on_pre_enter() and on_pre_leave() can be useful, thanks for the idea, now my solution is to call request_interstitial() at main screen init and at changing back to main screen from the other.