Most enterprise mobile apps require enterprise-level authentication mechanism. In that case, people use tried and tested Active Directory Authentication Library (ADAL) or Microsoft Authentication Library (MSAL). ADAL is in GA and it works fine with cross-platform mobile apps built using Xamarin. However, MSAL is in ‘preview’ and it offers nightly builds to try out. I wanted to try the latest nightly build (ver: 1.1.1-alpha0417) as it uses updated Android Support Package and old preview bits of MSAL (ver: 1.1.0-preview) were not compatible with latest Xamarin.Forms anymore. Here, I was trying to build one app over holidays and I got stuck on one interesting issue. Let’s discuss it in this blog post.
When you create a blank Xamarin.Forms app, it automatically references Xamarin.Forms NuGet along with all the required dependencies.
At this time, when you’ll try to install MSAL, you may get stuck at this issue of versioning.
The reason being Xamarin.Forms NuGet requires a specific version of Android Support Packages whereas Microsoft Authentication Library requires anything above Ver. 25.3.1.
Sometimes, things are very simpler than it looks. I spent a lot of time on solving this issue but was unable to fix it. Thanks to my friend Nish, who helped me with his ‘ problem-solving skills’ and we got this working.
The solution is simple:
- Remove all NuGet packages from Android project. For the sake of it, close and restart Visual Studio.
- Open the solution and Install MSAL NuGet package first.
- After installing MSAL NuGet, install Xamarin.Forms NuGet package.
Now you can build Xamarin.Forms apps with Microsoft Authentication Library. If you want to know more about how to use the SDK, follow the blog post here on Xamarin blog.
Even though I’m talking about Xamarin.Forms and MSAL here, this blog post is very much applicable wherever you’re trying to use any NuGet package which has updated dependency on Android Support Package.
Visual Studio Enterprise 2017 Preview (15.5.2)
Microsoft Authentication Library (1.1.1-alpha0417)
My friend Prachi tagged me on this meme on Facebook and I couldn’t agree more with her. When I started my career, my entire version control was folders – zipped, tagged and stored on multiple hard-disks. But then things changed. My guru Raj, enlightened me about advantages of version control systems. I learned about how multiple people can collaborate on projects or how errors can be reversed by going through code history if version controls like Team Foundation Server or GitHub are used. I started using those and these days, all my projects and samples are either in Visual Studio Team Services or in GitHub repository. Going one step ahead, I’m using Visual Studio Mobile Center for DevOps along with these version control systems.
But what is this all about? How it helps in building successful mobile applications? And I thought about answering these questions in a video series. The goal is to explain mobile DevOps and different steps in mobile DevOps in small (less than 10 mins) videos. After completing this series, you’ll be able to build cross-platform Xamarin.Forms mobile application, which will consume Microsoft Cognitive Service and set-up mobile DevOps for the same.
To follow along with this series, I’m recommending following minimum hardware/software combination:
- Intel i5, 8GB, 50GB machine with Hyper-V support & Windows 10 Professional
- MacBook or MacMini with i5, 4GB, 50GB for compiling iOS apps
- Visual Studio 2017 Community Preview
With these hardware/software additional services used in this series are:
Watch the 1st video here about activating these tools & services to set-up mobile DevOps.
In 2nd video learn about how to setup build automation, using Visual Studio Mobile Center.
I’ll update this blog post in coming weeks with the 3rd video in this series, which will be about building mobile applications.
Stay tuned and subscribe to my blog/channel :)
In previous episode of tendulkar-uvāca, we’ve seen how we can setup our development environment using Visual Studio and Xamarin.
In this episode, we’re going to see how we can use emulators to test and debug our applications.
iOS simulators will get installed with XCode is installed.
For Android emulator, install Xamarin Android Player from here
Windows Phone emulators can be installed while installing Visual Studio 2013 Update 3.
Do let me know your feedback and suggestions.
In our series on plugins, today we’re going to cover plugin which can help us to work with Accelerometer sensor. This sensor is responsible to detect X, Y, Z co-ordinates of the devices. Using data received from this sensor, you can build games like TempleRun, where users can collect the coins by tilting the device.
There are different APIs for different platform and their usage is different too. First, lets see how we can use this sensor in different platform and then we’ll use plugin in Xamarin.Forms application.
Being Windows Runtime API, the API and its usage is same in Windows and Windows Phone. Here, you create object of the sensor and register for ‘ReadingChanged’ event. Whenever device position is changed, it is reported through that event and UI can be updated using Dispatcher.
In case of Android, it is again similar to Windows platform. Create object of SensorManager and register for SensorChanged event.
iOS is not any different. You create object of CMMotionManager and then listen to sensor for changes.
As you can see, for three different platforms the APIs are totally different. But with Plugins for Xamarin.Forms it becomes easy. You can use DeviceMotion plugin which can work across all these platforms. And the code for same looks like:
In this series on plugin we’ve seen how particular concept can be implemented in all the three platforms and how we can use plugin to make life easier. This will be be last post in this series, but there are many plugins available which you can explore and use in your projects. Do let me know if you want to cover any specific plugin. We’ll start with a new series in couple of weeks. Till then… happy coding :)
In continuation to blog posts in this series on plugins, today we’ll cover a plugin/library to perform FileIO.
There are different APIs on different platforms to perform FileIO. Having said that, Xamarin already makes life easier by implementing System.IO which is available in Android and iOS.
Following code can be used in Android to create a file and then read contents from it.
Similarly, following code can be used in case of iOS application.
In case of Windows, using WinRT APIs, the case is little bit different as shown below:
Now to make life easier, there is a NuGet from Daniel Plaisted, which can help you to use same code on different platforms. You can find more information about the library from here: https://www.nuget.org/packages/PCLStorage/
This way, you can use one code (in C#) across all the three different platforms.
Hope you’re enjoying this series. Do let me know your feedback if you want to include any specific libraries/features.
In continuation to blog posts in this series on plugins, today we’ll cover a plugin to make phone calls.
As we understood before, all platforms support phone calling (just like emailing, texting, etc…) and Xamarin makes it easier with one common language – C#. However, developers still need to learn
In case of Windows Phone, one can initiate a phone call by using following code. In this case, Windows Phone has special class which allow developers to perform this task.
In case of Android, developers can use ‘Intent’ and ‘URI activation’ to start a new phone call.
In case of iOS, same concept of URI activation can be applied. As shown below in the code, developers can create a URI with telephone number and it will launch default application to make a phone call.
Now, in case of Xamarin.Forms developers can use same Messaging Plugin for Xamarin and Windows plugin to implement phone functionality across the platforms.
This way, developers can utilize the power of plugins to write one code which can work across different platforms, without bothering about underlying APIs.
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.