Home > Enterprise >  How to migrate users' local data when migrating from Xamarin to React Native Expo
How to migrate users' local data when migrating from Xamarin to React Native Expo

Time:01-06

I have a Xamarin Forms mobile application where local data is saved in multiple txt files. The same app has been developed with Expo React Native and uses AsyncStorage to store the users' data. When users update the app, I want to migrate the local data from the Xamarin Forms app to the React Native Expo app.

This is the code where I create the txt files in the Xamarin app

const string DATA_FILE = "DataFile.txt";
public static string savingsGoalFilePath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), DATA_FILE);
  1. What would be the location to the files in both iOS and Android?
  2. How to access these files in the Expo RN application to migrate the data?

CodePudding user response:

To answer question 1:

On Android, the LocalApplicationData maps to INTERNAL_STORAGE/.local/share.

On iOS, I believe that it maps to \Directories.

Both of these directories are sandboxed to only your app and the OS, which makes your question number 2 slightly more difficult.

To answer question 2:

If you want to keep the data directly on the device -

The data needs to be written somewhere the app has access to read/write it. For Android, you have access to the external storage where you can write your Xamarin app then read it with your react app.

iOS however does not allow access outside of your app sandbox unless you use an app group.

If you have a backend that supports it -

Get your user's permission to backup and restore the data through an API and DB storage. This has the added benefit of persisting across multiple installs.

  • Related