Xamarin - Is it possible to avoid ADK uses?

Emixam23Emixam23 USMember ✭✭✭

I'm currently working on a project and I need to implement few features to be done, however, it's not possible and I need to be done as soon as possible.

I have a solution PCL (.NET 4.5, Profile=111) and for some reasons (that I don't understand from hours now), I can't install the following packages :

  • Stripe (The only one that can be installed is Stripe.net, but I can only install it on Android and iOS, not on the PCL part..)
  • Cloudinary (I tried all of them and... It's not compatible with .NET 4.5, Profile=111)

Do you have any idea or any work around to make it work? :/ I need stripe for payments and cloudinary for images hosting. It's already what the company is using so.. I have to adapt.

I was thinking about don't use any sdk and just do everything by myself, is it allowed/possible?

Thank for any help !

Answers

  • Vlad_ServitolaVlad_Servitola USMember ✭✭

    You can use Shared Project for PCL part. This way you only have to install packages to Android or to iOS project. And Profile will not be problem completely

  • Emixam23Emixam23 USMember ✭✭✭
    Using interfaces?
  • JamesLaveryJamesLavery GBBeta, University ✭✭✭✭

    Another approach - which I think you're alluding to in your reply "Using Interfaces" is to (wait for it) use Interfaces.

    1. Install the Packages in your platform-specific projects.
    2. Create an Interface for each package which contains the methods/properties you need to invoke/access from your PCL.
    3. Create an implementation of the Interface in each platform-specific project which calls the package methods.
    4. Register the implementation with the Dependency/IoC container on each platform.

    This does seem a bit heavyweight though - you'll have to create the (admittedly probably pretty lightweight) Interface implementation classes for each package and platform.

  • Vlad_ServitolaVlad_Servitola USMember ✭✭

    @Emixam23 Sry for not answering
    Why didn't you just get Shared project? Works great for me.
    Shared project has no nuget packages dependecies itself. It uses all packages from your Android or iOS project.
    use interfaces and IoC than is great option, but you should try Shared Project

  • Emixam23Emixam23 USMember ✭✭✭

    It works with Xamarin :) I have a Xamarin solution (.NET Core 1.6, Android 7.1, iOS, UWP Build 16299)

    There is an example of how you can use it:

    public class CloudinarySDK
    {
        private Cloudinary cloudinary { get; set; }
    
        public CloudinarySDK()
        {
    
        }
    
        public void Init()
        {
            Account account = new Account(
                    "my_cloud_name",
                    "my_api_key",
                    "my_api_secret");
    
            cloudinary = new Cloudinary(account);
        }
    
        /// <summary>
        /// Upload a file by its path.
        /// </summary>
        /// <returns>The upload end path.</returns>
        /// <param name="path">Path.</param>
        public async Task<string> Upload(string path)
        {
            ImageUploadParams uploadParams = new ImageUploadParams()
            {
                File = new FileDescription(path),
                PublicId = String.Format("{0}.{1}.jpg", User.GetUserInstance().ID, DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss"))
            };
            ImageUploadResult uploadResult = await cloudinary.UploadAsync(uploadParams);
    
            return uploadResult.Uri.ToString();
        }
    
        /// <summary>
        /// Delete the specified url.
        /// </summary>
        /// <returns>The delete.</returns>
        /// <param name="url">URL.</param>
        public void Delete(string url)
        {
            DeletionParams deletionParams = new DeletionParams(url);
            cloudinary.DestroyAsync(deletionParams);
        }
    }
    

    Hope it helps !

Sign In or Register to comment.