Xamarin provides native, cross-platform mobile application development using language we all know and love – C#. However, it is still required to learn concepts of each platform. For example to send text message (SMS) in all these three platforms there are different set of APIs.
Below API is for Android, which uses SmsManager to send the text message. There is another way to do this using Intents.
In case of Windows Phone, ChatMessage allows us to declare and send text message. This API is available in WinRT platform. In case of SL based apps, we need to use Launchers/Choosers.
In case of iOS as shown below, there is no API as such. But we use URL to launch default messaging app. In this case, we cannot set the message body, which we want to send out.
Life will be much simpler if there will be just one API on all these platforms which will take care of sending text messages and as I developer we don’t need to bother about on which platform it is being called. Here comes components and plugins. My friend James has written a nice blog about ‘What Exactly is a Plugin for Xamarin?’. You can read it here
In our case, we’re going to use Messaging Plugin for Xamarin and Windows which allow us to use same API to send text messages. Below code is written once in a Xamarin.Forms project which depending on platform on which code is executing, send the message using that platform’s APIs.
Using this plugin, it becomes easier to send text messages on Android, iOS and Windows. And this is the magic of Plugins for Xamarin.
In future posts, we’ll cover some of the best plugins and components which can help you build cross-platform mobile applications with single code-base.
I hope you’ve enjoyed this.
Namaste
Mayur Tendulkar