larpon / QtFirebase

An effort to bring Google's Firebase C++ API to Qt + QML
MIT License
284 stars 83 forks source link

Interstitial ads `closed` signal not call in QML #122

Closed daljit97 closed 5 years ago

daljit97 commented 5 years ago

So I have the following code in my QML and the AdMobInterstitial loads just fine. However, when I close the ad the closed signal is never called. I have also tried to debug the project and set up some break points in https://github.com/Larpon/QtFirebase/blob/e0a982c4442267e62e653186f07a548aa678df40/src/qtfirebaseadmob.cpp#L987 however they all go untrack which suggest that the slot is never called.

    AdMobInterstitial {
        id: interstitialAd
        adUnitId: "myid"

        onReadyChanged: if(ready) load()

        onClosed: {
            console.debug("Interstitial AD closed") // this is not visible in the console
            load()
        }

        request: AdMobRequest {
        }

        onPresentationStateChanged: {
            if(state === AdMobInterstitial.PresentationStateHidden)
                load()
                console.log("AdMobInterstitial","::onPresentationStateChanged","PresentationStateHidden")
            if(state === AdMobInterstitial.PresentationStateCoveringUI)
                console.log("AdMobInterstitial","::onPresentationStateChanged","PresentationStateCoveringUI");
        }

        onError: {
            console.log("Rewarded failed with error code",code,"and message",message)
        }
    }
larpon commented 5 years ago

@daljit97 - hmm... that's weird.

Can you provide a little more context, like:

Also - have you tried moving the emit closed(); line up - to see if it's never called at all?

daljit97 commented 5 years ago

So I am testing on Android. Ok wait so when is the closed signal be supposed to emit? When the the user "closes" the ad clicking on the "x" at top of the screen? Because I am expecting it to do so when the user clicks on "x" but your third point seems to imply something else.

larpon commented 5 years ago

@daljit97

Ok wait so when is the closed signal be supposed to emit?

It's supposed to emit after onPresentationStateChanged changes to Hidden state. It's added as convenience signal AFAIR. onPresentationStateChanged should tell you the same.

I'm just asking to be sure that you don't expect it to emit when the app is exiting. Qt's event loop is usually shut down during these app lifecycle events :slightly_smiling_face:

So if onPresentationStateChanged works you can use that - although onClosed: { ... } should work according to this code section

... otherwise it's a bug

daljit97 commented 5 years ago

Sorry for my late reply. I have tested it again and I can confirm that closed is not triggered. In my debug output I can see:

 qml: AdMobInterstitial ::onPresentationStateChanged PresentationStateHidden

but the output Interstitial AD closed is never seen.