If there is no definite object or variable, how to judge the null?

the problem is this:

background: our company does mixed app, and I develop some web pages in app.
in mixed app, there will be an Android object in webview, which is a callable object exposed to me by my Android colleagues. Through this object, I can call some Android methods to achieve the purpose of linkage and interaction between the two functions.

requirement: a certain requirement requires me to call the method written by my Android colleague: Android.getUserInfo (), get the userInfo after calling, and then make a judgment.
but this getUserInfo () method is only available in the app package after a certain version (assuming 5.0), so it needs to be compatible with the older version of the app package.

my attempt: I directly wrote a let userInfo = Android.getUserInfo ()? Android.getUserInfo (): "default";

at that time, I thought I had solved the problem, but who knows, the above code was reported wrong because of getUserInfo is not defined, and what is more embarrassing is that the later code is not executed. Burst.

I would like to ask you if there is a way to achieve this compatibility between the two situations.

May.02,2022

  

our project handles this situation by writing a method to determine the client version, and then controlling it according to the version. This advantage is that you don't have to make a judgment for every new method.

Menu