adjust / flutter_sdk

This is the Flutter SDK of
MIT License
58 stars 49 forks source link

Return type mismatch in `getAppTrackingAuthorizationStatus` #122

Closed themartorana closed 5 months ago

themartorana commented 9 months ago

Adjust Flutter lib version 4.36.0, Android version 13

When calling getAppTrackingAuthorizationStatus a string value is returned from the method channel which it tries to load into an expected int var, and throws

_TypeError (type 'String' is not a subtype of type 'int')

adjust dart — platform_client 2023-12-11 at 3 27 52 PM
AMfaraz commented 9 months ago

The return type mismatch in getAppTrackingAuthorizationStatus was due to the expected result being an int, while the method originally returned a different type. To resolve this, I used the int.parse function to convert the result appropriately.

Example Solution:

String authStatus = await _channel.invokeMethod("getAppTrackingAuthorizationStatus");
// Resolved code using int.parse
int authenticationStatus= int.parse(authStatus);
return authenticationStatus;

I have created a pull request to resolve this

ramin-deriv commented 7 months ago

Hi Any update on this?

uerceg commented 7 months ago

Hey guys,

Sorry for the delay on this one. @themartorana thank you for reporting, @AMfaraz & @ramin-deriv thank you for going extra miles in opening the PR as well, really appreciate all the effort. However, I don't think that we will proceed with adding changes from that PR because from what I can see, they are trying to solve the issue in the wrong place.

Originally reported issue is that invocation of getAppTrackingAuthorizationStatus on Android platform is throwing the above mentioned error. And indeed, that's the issue. Now while looking a bit more in depth, not just with that method, but the same issue should happen if one invokes requestTrackingAuthorizationWithCompletionHandler (again) on Android platform. Dart layer is expecting integers to be sent from the native layer which is true in case of iOS:

However, it's not the case in native Android implementation:

As you can see, strings are being returned in Android and that's the reason for this error and why the suggested PR is not the way to go; one doesn't need to change Dart layer to expect string to be returned from the native layer - it should not be happening. The way to go is to make Android native layer to return an invalid integer value in these situations (which is -1, like in native iOS SDK implementation).

We'll ship the patch update with this fix shortly. I'll keep you posted.

uerceg commented 7 months ago

We have just released v4.37.1 update which should hopefully address this issue. If you can give it a shot on your end and let us know if it fixed the issue (or not), that'd be great. Looking forward to hearing back from you.

uerceg commented 5 months ago

In case you end up having any issues / question around this topic, feel free to comment / reopen. Cheers.