1
\$\begingroup\$

I am working on Xamarin forms project that targets three platforms (Android, iOS, UWP), and I was wondering which better to use Plugins or it's better to use DependencyService

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/

if my Example I need to retrieve some data from each platform like Version, DeviceName, OS ...etc

I created interface

public interface IAppVersion
    {
        string GetAppVersion();
        string GetDeviceName();
        string GetOS();
        string MailEOL();
        int GetOSMajorVersion();
    }

and start to implement my interface in each platform

[assembly: Dependency(typeof(VersionDroid))]
namespace CrewBriefingForms.Droid
{
    public class VersionDroid : IAppVersion
    {
        public static bool FormsInitialized = false;
        public string GetAppVersion()
        {
            Context context = Forms.Context;
            string version = context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
            return version;
        }

        public string GetDeviceName()
        {
            return Build.Model;
        }

        public string GetOS()
        {
            return "Android SDK: " + Build.VERSION.Sdk + " " + Build.VERSION.SdkInt.ToString();
        }

        public int GetOSMajorVersion()
        {
            return (int)Build.VERSION.SdkInt;
        }

        public string MailEOL()
        {
            return System.Environment.NewLine;
        }
    }
}

what I find plugin do the same job, should I go for using a plugin or implement my own code

and one more question according to code review should I create many interfaces as my interface name called Version and I ask for more than the version

\$\endgroup\$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.