We have a SDK shipped in two native libraries, let's say lib.framework
for iOS and lib.aar
for Android.
We needed to create a version for Xamarin, so we created a binding library for each of them (lib_ios_binding.dll
and lib_android_binding.dll
).
On top of this we created another abstraction level to enable the use of our SDK from Xamarin.Forms projects, a PCL made up of lib.dll
, lib.ios.dll
and lib.android.dll
. This level provides a set of interfaces (lib.dll
) which are implemented in both native libraries (lib.ios.dll
and lib.android.dll
) and the instances are resolved at runtime by the Dependency Service.
Our approach for consuming the server API in the native libraries is implemented by delegates/listeners. The delegate/listener of each operation is passed through the invoker method and called back once the response is received. We handle threads natively, by sending the operation to a background threads and returning immediately. Once the operation is completed (it could take a while) we call back the listener/delegate on the main (UI) thread.
Now we are requested to use the async / await approach by an integrator but we are not able to make it work properly.
As for now we have tried to use the TaskCompletionSource
in the PCL level, but we are losing context as we are not being called back all the times. The delegate/listener is not being invoked properly. We can assure the requests are being launched and they are reaching the server.
So we need a way to create something like a task to run the native request and be able to wait until the response is received and return the result.
Is this possible to achieve? What are we misunderstanding or doing wrong?
Any help would be highly appreciated.