Idea:
I work for a fairly young and inspired company, and we always happy to be useful for ours customers and companions. But sometimes you can have situations, when you need somehow to regulate using of results of your time and efforts. So, issue of protecting our applications was open, until recently. The idea was to have simple control mechanism for Xamarin.Forms maded applications without any uncomfortable for customers or our co-workers outcomes.
Approach:
When we thought about way of implementation for our idea, we keeping in mind gold standard of codding: code should to be clear, code should to be simple. Its inspired us to create minimalistic, but effective and whole design for realization of this task. At least, what do we need as minimum to have such functionality?
1 - some "control panel";
2 - "bindings" with applications, and
3 - "hooks" in those apps.
So, lets go by steps with it:
1) Good for this purposes is some cloud service with switchers. We choose ConfigCat, because it have all necessary functionality (a way to get data from cloud included), it is simple and user-friendly. May be, it is trite, but the last point was very appreciate for us, it indicates aspiration of this company to give us good experience. Because we try to be so.
2) Of course, to write the same RestApi clients , response handlers, alert sections and e.t.c.in each our Xamarin application is not the way. And it is a bit too visibly for this kind of purposes. So, decision to have all our code in nuget package was optimal.
3) For integration of our package in different Xamarin.Forms applications, we need some way to initiate our package without additional preparations or some garish parts of code. So, all necessary logic should be hided in one init method with simple name. To know specific application, we decided to use its bundles.
Using:
To use our package, user just have to install it to shared project (available on NuGet: https://www.nuget.org/packages/Xamarin.Security ) and call XamSecurity.Init(...current application...) method:
XamSecurity.Init(Application.Current);
or:
XamSecurity.Init(this);
depends on place of application, where you use it: first variant is for OnAppearring() / OnDisappearing() methods, and second is for calling in App.xaml.cs class of your Xamarin application (about it a bit later). Calling this method is only one necessary and available part
of plugin for users.
When it calls, it checks "legal" status of this application flag (and get needed for alert page data). If status is wrong, it immediately destroys Xamarin. Forms application's navigation stack and navigates to alert page. So, you cant go anywhere from this page, except contained web address, or closing application. As you see, Init(...) method should (and can be) called in any place of application, where you want this check to be triggered. When application started, or when any page appearing/disappearing - as you wish.
Page design can be adapted to your choice: logo image, web link with your address, page and text colors. We need just those values, and all other things we will manage by ourselves.
Summing up:
As a result, we have a simple and easy-to-use plugin for Xamarin.Forms. I also hope that, among other things, this article will help you feel less constrained in your various endeavors, no matter how simple or complex they may seem, and you find something yourself for yourself. Good luck!
Comments