influencemobile / cordova-adcolony-plugin

MIT License
5 stars 8 forks source link

Callback of failure on iOS devices causes "Invalid callback id received ... #7

Open davyboyhayes opened 9 years ago

davyboyhayes commented 9 years ago

...by sendPluginResult" calls to occur. This fixes this by changing the order in which the self.callbackId is set around the AdColony calls, and removing a line which set the value of the self.callbackId to nil while an active advert was playing.

Testing locally when AdColony isn't providing ads, I was noticing that the "Invalid callback id received by sendPluginResult" message was appearing in the logs, and more importantly, my failure callbacks weren't being called despite the ad definitely failing. Digging around a little, it appears that in some situations, the callback from the AdColony code for saying that an error has happened, via the delegate, is occurring as part of the show video ad call, and not asynchronously. This causes a failure, because our delegate hasn't had self.callbackId set yet, as it is due to occur after the AdColony call.

This PR changes this order, so that the delegate always has the correct callbackId.

I also noticed an interesting code path which is when AdColony notify us that the ad is playing in the zone... we set the value of the self.callbackId to nil, yet we know that at some point down the line, we are going to get an onAdColonyAdAttemptFinished command which in an error state, requires the self.callbackId.