We are getting following exception when we try to call storagefolder.getfilesasync() method in Xamarin Forms UWP enviornment.
is ther any alternative to that?
I suspect the reason is that you are trying to use files inside the shared Portable Class Library. Because this library is shared across UWP, Android and iOS, you can't use Windows specific StorageFile there.
To work around this, you will need to create an interface for file access and implement it for each operating system separately. Working with files is very well described in Xamarin Documentation.
Related
So, I have been developing an android app for some time, and I was requested to try porting this app to windows phone too. In order to reduce the hassle in trying to maintain two separate versions of the same app, I decided to try to port this app into xamarin, because I have heard that its performance is better than hybrid apps. These are my questions with regard to xamarin:-
I want to maintain the same look and feel which I had in my original app into my cross platform app, and at the same time, make it distinct in the windows version. What are the things I can do to achieve this effect?
Is it rather better for me to port this app to windows phone native, because of added problems in trying to create a common app?
Are there any restrictions with regard to Windows store when publishing xamarin apps?
Xamarin doesn't really cover Windows UWP apps, only in the notion that they have the UI Framework Xamarin.Forms running on that platform. Meaning, that what you are making is a native Windows UWP app.
What Xamarin is great at is when you start targeting more than one platform and you have structured your code in a way that it can be reused on the supported platforms. This could for instance be done by putting most of your logic and behavior into a Portable Class Library/NETStandard library and consume it in your apps.
A Typical pattern for making platform agnostic logic and behavior for your apps, is the pattern known as Model-View-ViewModel, where the View is platform specific, while the Model and ViewModel usually are platform agnostic. The ViewModel is where the behavior resides and it is what ties the Model together with the View.
Usually the ViewModel wouldn't directly know the View, but there would be a layer in between (glue), such as XAML or a binding engine from MvvmCross, MvvmLight or ReactiveUI to name some MVVM libraries.
What Xamarin provides is the ability to write C# code for Android and iOS, which greatly enables you to share code between those two platforms, but also all the Windows platforms. Hence, UI, is very much dependent on each of the platforms on their own.
You can, of course, use Xamarin.Forms as a UI abstraction layer, which produces a native UI using the native UI controls to get a similar app on all the targeted platforms.
First of all you need to know there are different styles of Xamarin development, who will share more or less content.
If you use Xamarin Forms you have a Main project non-related to any platform (where you create the views and clases), and specific platform projects who adapt the controls to each native style.
If you develop using Xamarin Classic, you have a Shared project where you only develop data-related classes, and specific platform project with their own views and classes with native-friendly controls and native similar functions, but I think, there is no direct Xamarin Clasic Windows Project.
So if you only want to have two apps who look native both, but with same structure and functionalities Xamarin Forms will be the best option for you, cause you only develop "one single app" who becomes native-style like this:
If what you want is to have different apps, with different functionalities and diferent content, then you need to go for Xamarin Classic. What I recomend you to do then is develop the windows phone in native, but put all of the code you can in a shared library. Then you can create a Xamarin classic Android app and use the shared library. You will still need to mantain two different apps, but you will only need to change the "core" code only one time.
If you use Xamarin Forms to do a UWP windows app I don't think you have any problem to publish it, think Xamarin is from Microsoft.
I need to implement a dead reckoning application using xamarin. In order to do this, I need to access the pedometer/accelerometer from Android/ios and windows phone. Since they have their own APIs to be called, I believe the approach would be to create an interface in the PCL project and then have native implementations for each platform. These could then be made visible using assemblies. Apart from this, are there any approaches using which the entire code can be implemented in the PCL project itself? Without having native implementations for each platform?
The logic of your app can be done in the PCL but calling the pedometer or accelerometer must be done natively.
The basic approach is (just an example)
public interface IPedometer
{
int GetSteps();
}
and this interface is in your PCL.
On each native platform create a class (e.g. NativePedometer), implement this interface and natively code to get the result.
Use dependency injection on each native platform, e.g.
DependencyService.Register<NativePedometer>();
Then just use the below in your PCL.
DependencyService.Get<IPedometer>() and perform the business logic in your PCL. This allows you to reuse as much code as possible across platforms.
It is the best approach but you can't avoid writing native code and by native code I mean C# in the traditional/native Xamarin projects.
I need to create a application which would take the preference of the user when starting the application for the first time and then the appropriate module would be downloaded for the application. Is it possible using xamarin.forms?
Currently we are using xamarin.forms PCL project and creating app for android and iOS using xamarin.forms.
I don't see why not, though you'd likely be tied to Android. Dynamic execution on iOS is not supported, and I'm not sure about Windows. It should be an easy enough test: click a button, download an assembly from somewhere, dynamically load it, then instantiate a class that implements an interface you're looking for. I've been wanting to do a blog post on this very thing, but alas...
Another option which may be iOS compatible is having some code in JavaScript, then download and run it in a WebView. Though that may be more trouble than it's worth.
I'm having trouble getting my shared project to work with my UWP application. The shared project uses Mono.Data.Sqlite for the database connection and it works on Android and iOS, but I don't know what reference I'm missing since it doesn't recognize the library on UWP. Anyone tried this before?
On Windows Phone the SQLite engine does not come by default so you need to add support for it. This is an easy step. Just add the precompiled binaries. A way how you can do this can be read here.
This is why the Mono.Data.Sqlite namespace will not work on UWP applications. To work around this issue you have to use compiler switches. For example:
#if !WINDOWS_PHONE
using Mono.Data.Sqlite;
#endif
#if WINDOWS_PHONE
using Whatever namespace it is.
#endif
This will work with SharedProjects. An other option would be a PCL (Portable Class Library) that contains your shared code. With this you can use the SQLite-NET – Cross-Platform ORM.
I have a dot net dll which uses System.Drawing.dll for using classes like Bitmap, Rectangle,Size etc.. But my dll cannot be used on xamarin... Plz suggest me what else should I use in my dot net dll for using Bitmap etc.so that it can run on xamarin.
Your dot net dll is complied for specified platform, such as Windows. so you cannot use it in other phone OS. It is no way for you to directly use dll in Xamarin unless you build it for portable class. But portable class is a generic class base, it lack of lots of classes. Such as Bitmap, it is different in different OS like Nick Turner said, so you will failed to build your source file.
The best way, you can reuse some none-platform dependent code in you dll, but for others, you need to write new code in each Android, ios, winphone project. So the Xamarin is not so wonderful for writing once, using every where. There is still lots of work in Xamarin, especially for platform specific code.