Xamarin.Forms Twilio implementation
This project you can find at: https://github.com/officialdoniald/Xamarin.Forms.Twilio
Twilio created just for Android and iOS libs and not for Xamarin. So we need to create Bindings for Xamarin.Forms and native.
First step: we need to create Android Binding Library(https://github.com/officialdoniald/Xamarin.Forms.Twilio/tree/master/Xamarin.Forms.Twilio.PoC/Xamarin.Android.Twilio.Client) and iOS Binding Library(https://github.com/officialdoniald/Xamarin.Forms.Twilio/tree/master/Xamarin.Forms.Twilio.PoC/Xamarin.iOS.Twilio.Client) in an Emptys Solution. We have to add the .aar/.jar file(to Jars folder to Android) and .a files (as native reference to iOS) to the Projects. But if you want to just using the completed DLL, just download theese Project from my GitHub, Clean and Rebuild and use the builded DLLs or just added theese Projects to your Application Project as Reference.
After this we need to create a Xamarin.Forms Application(https://github.com/officialdoniald/Xamarin.Forms.Twilio/tree/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC).
We need to add the DLLs or the Projects as Reference to the various Platforms Projects.
Super! We can use the Twilio lib from the Android and iOS Projects. But if we want to use theese from the Forms Application we need to create some Platform Specific implementations and we will call theese throught DependencyService.
Let’s create an Interface in the Forms Application: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC/Implementation/Twilio/ITwilioClient.cs
Now we have to create some events. We will implement the MakeOutBoundCall, Mute and HangOut functions from Twilio. https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC/Helper/GlobalEvents.cs
Great! Now just implement theese in the various Platforms and we will talk about what have to do, when we want to use theese functions without crash.
Let’s create the interface imaplementation: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC.Android/Implementation/Twilio/TwilioClient.cs
Open the MainActivity.cs and create the Twilio object.: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC.Android/MainActivity.cs
Very important: we need to change our AndroidManifest.xml file: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC.Android/Properties/AndroidManifest.xml. We need to add some uses and service.
Don’t worry, if there will be some errors, that’s a Visual Studio bug. The project will be built.
Let’s create the interface imaplementation: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC.iOS/Implementation/Twilio/TwilioClient.cs
And here we will use the microphone we have to change the Info.plist file: https://github.com/officialdoniald/Xamarin.Forms.Twilio/blob/master/Xamarin.Forms.Twilio.PoC/Xamarin.Forms.Twilio.PoC.iOS/Info.plist
<key>NSMicrophoneUsageDescription</key> <string>YOUR_APP_NAME will use your microphone, when you call someone.</string>
When you make an OutBoundCall you can use a lots of combination of the parameters. See some of theese at: https://www.twilio.com/docs/voice/client/tutorials/outgoing-calls.