Download a zip file using xamarin forms app - xamarin

I Am Newbie in Xamarin. Our Xamarin forms app supports Android and IOS. Most of the app functionality is written in PCL class library which is referred in the above platforms.
Now we need to download a zip file using this app. Some posts are suggesting to handle it in common PCL library and some are suggesting to handle it in respective native projects. I am bit confused, which is the better approach of the two. Are there any limitations in this approaches?
If possible could you please share a sample app. Thanks in advance.

You can write the code to download the file in PCL. For downloading file you can make use of HTTPClient. At the same time you have to call dependency service and write the dependent code in corresponding android/ios projects to specify the file output path.
https://developer.xamarin.com/recipes/ios/network/web_requests/download_a_file/ uses webClient which is written in android. You can use HTTPClient to get same result in PCL

Related

Libgit2sharp in Xamarin iOS

I'm trying to run Libgit2Sharp in a Xamarin.iOS project (I'm currently running it on Xamarin.Droid).
For doing so, I was trying to follow the same approach than for Android (generating a custom native binaries package) but I have faced some doubts/problems.
First, iOS doesn't allow the use of dynamic libraries at least if you want to upload the app to the market.
Is there any "easy" way no rebuild libgit2sharp to make it run static libraries?
Probably the App will not go to the official App Store, but it would be nice to know if it is possible.
Another thing I have realized while checking the libgit2sharp source code is that iOS is not in the list of possible Operating Systems, so should I make any other modification to make it run on iOS?
Thanks in advance
So in the end I found a way to run libgit2 in Xamarin.iOS.
Basically what I did was to generate the iOS libgit2 static libraries (you can use the Objective-git repository for doing so, as it is part of the process) and then modify LibGit2Sharp project to look for "__Internal" instead of the .dll/.so dynamic libraries.
The you just need to add the libgit2 static library to your Xamarin.iOS project, and that's all.
Hope someone finds this info helpful.

Cannot add Judopay to Xamarin forms project

I am trying to include Judopay in my project, and I was able to add it to Android and iOS, but not to the Xamarin forms project. There is no NuGet to be included and I can't seem to add the component reference. Any idea on how can I add it? I cannot use any of these:
using JudoDotNetXamarin;
using JudoPayDotNet.Enums;
using JudoPayDotNet.Models;
Again, they only work on iOS or Android, but not Xam forms.
That is because they only provide platform implementations. You will need to tell your Forms app which implementation to use at what time.
The correct way to go about this is with some form of IoC, using dependency injection or service location. Luckily Xamarin Forms has this integrated:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/introduction/
Using the references from the Android or iOS projects in your shared code will likely not work completely or break things. Maybe not immediately but surely later on. (Except when there really is no platform-specific functionality, then you might get away with this.)

download files using document extension iOS

Can we download and upload files from server using document extension in iOS ? I read there is a method documentStorageURL , originalURL in UIDocumentPickerExtensionViewController class. But in my case I have a C++ SDK that downloads a file from a server. So it is possible to integrate a SDK in the extension target of my application and use the SDK to download the file from another third party application. Has anyone tried to download a file via iOS NSURLSession or NSURLConnection classes in a UIDocumentPickerExtensionViewController class? or is their any limitations for extension not being able to integrate normal iOS app functionality ? Any sample code or references will be great.

Integrating xamarin, CouchBaseLite, MVVMCross and SyncGateway such that View changes with database

I am working on a xamarin project where i use CouchBase Lite as my Local database. I also want to use MVVMCross library. Could anyone specify where should i include couchbase-Lite library, MVVMCross - hot tuna library(like class library or portable class library or platform specif project) such that view model gets notified about the changes in Couchdatabase.
Basically i want to change the view whenver there is a change in database i want to change the view with mvvmcross. Am using syncgateway to sync with server Couchbase bucket.
I am new to Xamarin, MVVM and CouchBaselite.
I couldnt find any concrete example for all this.
Thanks in advance.
I would perhaps just use the CouchBaseLite Xamarin Component. If you are wanting to access this in your PCL Core project you will probably have to create some sort of wrapper around the component and inject it properly into each platform. You can use the MvvmCross plugins wiki to get you started.
I know this is an old thread, but there's a new MvvmCross plugin for Couchbase, and basically does everything you want. It's in alpha, as of this writing on Nuget, and open source on Github. I was actually looking for the same, and happy to have found it! :)
https://www.nuget.org/packages/MvvX.Plugins.CouchBaseLite.ForestDB
https://github.com/mathieumack/MvvX.CouchBaseLite

Using HttpClient in a Xamarin core project

I am doing a project for multiple platforms where I have followed best practices and created a core project to contain all the code that is the same on all platforms.
To do the network communication I would like to use HttpClient which seems to be the recommended approach for communicating with web services going forward.
I am NOT doing a PCL but just a standard C# library to contain the core project. However it seems that there is no common implementation of HttpClient but only platform specific ones. I cannot reference and use it in my core but only in my Android and iOS projects.
I would very much prefer to have all networking code in my core project and as I see it there are two options - neither of which I like.
Make a common interface that I can use in the core project that is implemented as a wrapper on both Android and iOS.
Use another technology that is supported in the core project - I am thinking webclient or the like.
What is the recommended approach and why hasn't Xamarin made HttpClient available as a common library?
Hope someone can help,
Thanks
I recommend checking out ModernHttpClient https://github.com/paulcbetts/modernhttpclient
It is a cross-platform networking library for iOS and Android. From the project:
This library brings the latest platform-specific networking libraries
to Xamarin applications via a custom HttpClient handler. Write your
app using System.Net.Http, but drop this library in and it will go
drastically faster.
You should be able to use System.Net.Http in your core library just fine, I've done it recently.
Make sure your core library is a .Net 4.5 project. There is a setting in project options for selecting the .Net version. After checking this, all you should have to do is reference System.Net.Http.dll.
If that doesn't solve your issue, are you on Windows or Mac(Xamarin Studio)?
I'm afraid you can't use HttpClient on Mono at the moment due to licensing restrictions. There is a UserVoice suggestion that you can vote on if you like.

Resources