Jaa


Porting iOS Apps to Windows 8 (5): Storing Data and Preferences

Author: Rafe Wu

 

Channel 9 https://channel9.msdn.com/Blogs/OneCode/How-to-Port-iOS-apps-to-Windows-Store-apps

Windows 8 features a very comprehensive system of managing data for applications. This section compares the Application Preference features of Windows 8 and iOS.

Application Preference

The following table shows how we store application settings on the two platforms.

 

iOS

Windows Store Application

Application Preferences

System wide settings application

In-Application preference pages

In-Application settings charm

Preferred/Required

System wide settings application

In-Application settings charm

Preference UI

Declarative syntax for System wide Settings

Developer implements a page for in-app preferences

System provide an in-application settings charm.

Developer implements Settings Flyout

 

In iOS it is recommend to centralize the app preferences in system settings. There are some 3rd party libraries you can use to implement in-application settings. In Windows Store applications, the application settings are stored on per-application basis.

You can use ApplicationData.Current.LocalSettings property to save the preference locally. Or use RoamingSettings property so that other devices installed this app can also use these settings.

Generally you should load settings when the application is activated and store settings when the application exits. In Windows 8, you should fetch settings in OnLauched and Application.Resuming event handler, write data in Application.Suspending event handler.

Internal Storage

Besides settings, Windows Store applications can create files and folders in the StorageFolder. They use StorageFolder and StorageFile classes for folder and file operations.

Windows 8 provides four different folders to store the private data:

  • ·         LocalFolder: It’s used to save persistent data that exists only on the current device.
  • ·         TemporaryFolder: The data in the TemporaryFolder works like a cache. It can be removed by the system at the anytime. 
  • ·         RoamingFolder: The data in the RoamingFolder exists on all devices on which the user has installed the application.
  • ·         InstalledLocation: It’s a read only folder which contains the application package. 

External Storage

Windows Store application doesn’t provide the general external storage due to security reason. You can access some known libraries, such as Documents, Videos, Music and Pictures folders. But you should declare the capabilities in the manifest file before accessing. You can also access SD storage through RemovableDevices property.

For security reason, the Windows Store application can’t access arbitrary files in the device implicitly. If you do want to access a specified file, you should use file picker to select this file explicitly. Then the application gets the permission to access this file.

Summary

In this chapter, we compared data storage guidelines for Windows 8 and iOS. We also looked at the storage apis in Windows 8.

 

See also Porting iOS Apps to Windows 8 (4): Application Lifecycle Differences