One of the biggest challenges in Cross Platform Mobile App Development is implementing a mechanism of performing simple tasks on each diverse platform, such as reading a config file on app launch, when you know that each platform will store this file in a different location, have a preference for different file formats, and have different permission mechanisms for reading and writing. This plugin helps nail most of those issues.
Most mobile applications need to interact with the underlying file system. Be it building a database or caching data, some understanding of how file systems work on target platforms is required. If you’re working with multiple platforms, not only does this require understanding of how each individual file system works, but also how to work with the file system from shared code.
The File System Plugin for Xamarin and Windows reduces the underlying file system complexities for each platform into a cross-platform file IO API for iOS, Android, and Windows, making it extremely easy to work with the file system from shared code. In this blog post, you will learn how to use the File System Plugin for Xamarin and Windows to create, edit, and delete files and directories from shared code.
Introduction to the File System Plugin for Xamarin and Windows
Similar to desktop operating systems, mobile operating systems each have their own file system. Building applications that target multiple operating system requires knowledge of not just one file system, but the underlying file system for each platform. Another barrier when working with file systems is the inability to use code that talks to individual file systems in shared code. A common solution to this problem is to use preprocessor directives (#ifdefs) to access platform-specific features, but this won’t work with PCLs and results in messier code.
Plugins for Xamarin expose platform-specific functionality via a cross-platform API that can be consumed from a Portable Class Library or Shared Project, such as using device geolocation, sending an SMS, or storing app settings, to help make you share even more code and increase developer productivity. The File System Plugin for Xamarin and Windows makes working with the many different mobile file systems easy with a shared, cross-platform API. You can download the plugin using the Xamarin Component Store or via the NuGet Package Manager.
Exploring the APIs
The IFileSystem interface represents an abstracted file system at the highest level. The platform-specific implementation can be accessed via the FileSystem.Current property. The file system is made up of a collection of folders and individual files, which are abstracted via the IFolder and IFile interfaces. When creating folders and files, we are also given maximum control over collision detection preferences with theCreationCollisionOption enumeration, which allows us do everything from create an alternative name, replace the existing directory/file, open the existing directory/file, or throw an exception. Of course, all of these APIs are also async/await compatible as well.
// Access the file system for the current platform.
IFileSystem fileSystem = FileSystem.Current;
// Get the root directory of the file system for our application.
IFolder rootFolder = fileSystem.LocalStorage;
// Create another folder, if one doesn’t already exist.
IFolder photosFolder = await rootFolder.CreateFolderAsync(“Photos”, CreationCollisionOption.OpenIfExists);
// Create a file, if one doesn’t already exist.
IFile selfiePhotoFile = await photosFolder.CreateFileAsync(“selfie.png”, CreationCollisionOption.ReplaceExisting);
Renaming and deleting files is also super easy as well:
// Actually, this wasn’t a selfie of just me!
// It’s a horrible selfie anyways, let’s delete it!
In this blog post, you learned how to interact with native file systems for iOS, Android, and Windows from shared code using the File System Plugin for Xamarin and Windows. To learn more about Plugins for Xamarin or check out other plugins available, such as geolocation, messaging, and sharing, check out our complete plugin directory. Visit the plugin in the Xamarin Component Store for more documentation or view the source code online on GitHub.
Where we don’t have to build out some sort of bespoke mobile app sync, this is pretty much the standard way for us to sync files between cross platform and multi platform apps
In a mobile world, network outages are frequent. Devices are constantly moving and connectivity can vary from great to barely connected to offline, with users expecting your app to continue to function properly. For example, field technicians need the ability to log notes in their field service app, no matter the connection state. Apps can support offline usage by …
Xamarin Cross Platform Application Development – Book Review
Andy Flisher is a Software Developer based in the North East of England specialising in cross platform development. Mobile Development experience includes Windows Phone, Android, and iPhone Apps. Desktop Software Development includes bespoke Windows, Linux, and Mac Applications. Web Development Skills include PHP, Perl, Python, Xamarin, C#, ASP (Classic and .NET). Andy also has some Industrial / PLC Programming experience – Andy Flisher on Google+
This is a review of the recently published book “Xamarin Cross Platform Application Development” by Jonathan Peppers.
This book is openly marketed at existing, experienced C# developers so it’s certainly not for beginners, and whilst I don’t fall into this category the nature of projects I work in require mostly ‘linear’ development (Web, PHP, Perl, Python, VB etc over the years) so concepts like MVC, MVVM and in particular IOC (Inversion of Control) are newer and less clear. Thankfully this book has resolved that through it’s excellent practical examples.
One area this book doesn’t touch on hugely is the level of planning required for MVC applications, you can’t just ‘jump in and code’, but that’s potentially a book in itself, but what the book does very well for me, is explain the View, ViewModel, Model and Controller concepts in terms of the classes and data layers required. The book also introduces Interfaces (something I always saw as an unnecessary layer of complexity) which I now ‘get’ in terms of flexibility, and in particular to give the developer options in a cross platform environment.
The icing on the cake is ‘Inversion of Control’, whilst the book doesn’t particularly explain this convention in huge detail, I think it is actually to it’s credit, any more and the reader will be bogged down in unnecessary detail and complexity. It basically gives us the service layer that ‘glues’ the application together, allowing use to create and register our ViewModels as Services and thus make them available to use throughout the app with a single line of code. I’m sure that my description is not hugely more constructive than the words in the book themselves, but the working example of the XamChat application completes it.
Which is my main point, am sure many people work differently, but for me working examples of code are what makes it stick in my mind, it helps it all make sense. Throughout this book you will be building bit buy bit a working chat application, firstly in Xamarin.iOS (but using the all important cross platform and code sharing concepts learnt at the beginning of the book), and then re-implementing the same application logic in Xamarin.Android. The nice touch, which some may see as lazy, was that with the Android example you are taken to a certain point and then left to finish off using the examples you already have. A real, and practical exercise which I think will do the reader good. It wouldn’t be a huge leap further to recreate in Windows Phone, for the ultimate practical extension.
The Xamchat application is then extended through the Windows Azure platform to use their backend for data storage (a good example of how the same Interface can be re-used to store on different platforms), and to implement cross platform push notifications.
Lastly there are chapters on using Xamarin Components (including Xamarin.Mobile for Contacts, Camera and Location functionality), and actual App Store submission and their different processes, processes that even the most experienced developer can struggle with (Apple Certificates and Profile expiry anyone!).
In summary, this is an excellent book for any would be cross platform mobile application developer, yes you need a good understanding of C#, MVC and similar concepts, and the individual mobile platforms and general development processes themselves, and those things don’t come over night, but this book binds it all together with real world examples, working code (a novelty for some books) and actual code and methods you can take away and use in the real world.
Buy it, read it, and take as much as you can from it – “Xamarin Cross Platform Application Development” by Jonathan Peppers
Baby Biography Mobile App – Projects
Andy Flisher is a Software Developer based in the North East of England specialising in cross platform development. Mobile Development experience includes Windows Phone, Android, and iPhone Apps. Desktop Software Development includes bespoke Windows, Linux, and Mac Applications. Web Development Skills include PHP, Perl, Python, Xamarin, C#, ASP (Classic and .NET) – Andy Flisher on Google+
The mobile app will be developed using dotUK’s cross platform, and multi platform mobile app development skills. This skill set is a niche, and dotUK are one of the few development companies, certainly amongst North East Mobile App Developer’s to offer true, native mobile apps that can be developed simultaneously across the core mobile application platforms, in parallel.
The Baby Biography mobile app will be offered initially as an iPhone app, and also as and Android App, in addition to creating Baby Biographies within the app, other features include;
- Creation of Multiple Books
- Sharing of Baby Moments and Photos ‘In App’ to Social Media
- Free Cloud based storage of all your books and moments
- Collaboration with other parents
- Conception and Pregnancy calculators
- In App Support
Cloud storage and collaboration will be offered through dotUK’s in house cloud storage framework which allows the app to seamlessly synchronise the baby biographies into the cloud in the background when connected to a suitable internet connection, but doesn’t in any way impeded or restrict any app functionality when working offline.
Originally posted at http://www.dotuk.net/news…