admob_flutter icon indicating copy to clipboard operation
admob_flutter copied to clipboard

BUG 1.0.0-beta5 - Rewarded ads, "amount" parameter datatype (int on Android, double on iOS)

Open henry2man opened this issue 5 years ago • 4 comments

Using prerelease 1.0.0-beta5 with rewarded ads I'm having issues processing reward config in the listener code. The "args" map that contains the reward info (filled in AdMob) is not processed in the same way on Android and iOS. More exactly, the "amount" parameter, which natively is an integer, is solved on Android as an int (correct) but as double on iOS (incorrect).

In my listener code I had this:

...
 if (event == AdmobAdEvent.rewarded) {
     var amount =  var amount = args['amount'];
     print('Reward amount: $amount - type: ${amount?.runtimeType}'); // int on Android - double on iOS
...

The workarround for now is quite simple:

...
 if (event == AdmobAdEvent.rewarded) {
     var amount =  var amount = args['amount'];
     // BUGFIX amount parameter
     if (amount is double) {
        amount = (amount as double).truncate();
     }
     print('Reward amount: $amount - type: ${amount?.runtimeType}'); // now it's int on both Android and iOS
...

henry2man avatar Aug 27 '20 16:08 henry2man

@henry2man thanks for reporting this. Do you have bandwidth to PR a fix for this to make things consistent?

kmcgill88 avatar Sep 22 '20 13:09 kmcgill88

Honestly I don't have much experience with native iOS development (I suspect this needs some Swift/Objective C tweaking).

I will try to fix it but I cannot promise anything 😅

henry2man avatar Sep 22 '20 14:09 henry2man

Hey @henry2man, I can help you on this one if you want :wink:

Skyost avatar Sep 23 '20 11:09 Skyost

I did a fast bird's-eye view of this issue.

In this case the swift code is very straightforward... the code is calling Google Ads iOS SDK directly.

AFAIK the "amount" parameter should be an integer so it's likely a mistake in the Google SDK.

@kmcgill88 What do you think? Should we apply a quick-n-dirty patch until Google SDK is fixed?

henry2man avatar Sep 23 '20 19:09 henry2man