Xamarin.iOS- Storing Data

Xamarin.iOS can use the same System.IO classes to work with files and directories in iOS that you would use in any .NET application. However, despite the familiar classes and methods, iOS implements some restrictions on the files that can be created or accessed and also provides special features for certain directories. This article outlines these restrictions and features, and demonstrates how file access works in a Xamarin.iOS application.

Locations of Persistent Data

iOS provides several options for saving application data based on the specific needs of the app. Some apps require private storage while others need to share data between apps.

There are five different places to store data:

  • Shared Preferences – Stores data in key/value pairs
  • Internal Storage – Stores private data in the memory of the device
  • External Storage – Stores data, which can be available to other apps on shared external storage
  • SQLite Databases – Stores structured data in a private database
  • Network Connection – Stores data on a Web server

iOS imposes some restrictions on what an application can do with the file system to preserve the security of an application’s data, and to protect users from malignant apps. These restrictions are part of the Application Sandbox – a set of rules that limits an application’s access to files, preferences, network resources, hardware, etc. An application is limited to reading and writing files within its home directory (installed location); it cannot access another application’s files.

iOS also has some file system-specific features: certain directories require special treatment with respect to backups and upgrades, and applications can also share files via iTunes

This video will walk you through creating an app that stores information to a text file on the device. We will store some information and then retrieve it for display using  the .NET System.IO classes for file system operations on iOS.

Leave a Reply

Your email address will not be published. Required fields are marked *