Docs Menu

Docs HomeDevelop ApplicationsAtlas Device SDK

Bundle Realm Files - .NET SDK

On this page

  • Create a Realm File for Bundling
  • Bundle a Realm File in Your Production Application
  • Open a Realm from a Bundled Realm File

You might want to seed your mobile app with some initial data that will be available to users on the initial launch of the app. To do this, you:

  • Build a temporary realm app,

  • Make a copy of an existing realm (with only the data you want bundled), and then

  • Bundle the Realm file in your app's shared project.

In your production app (the one that will use this bundled realm when first loading), you add a few lines of code to extract the realm and save it in the app data. The following sections provide more information on these steps.

Important

Bundling Synced Realms

If your backend application uses Flexible Sync, users could experience a client reset the first time they open the bundled realm file. This can occur when client maximum offline time is enabled (client maximum offline time is enabled by default). If the bundled realm file was generated more than the number of days specified by the client maximum offline time setting before the user syncs for the first time, the user experiences a client reset.

Applications that perform a client reset download the full state of the realm from the application backend. This negates the advantages of bundling a realm file. To prevent client resets and preserve the advantages of realm file bundling:

  • Avoid using a client maximum offline time in applications that bundle a synchronized realm.

  • If your application does use a client maximum offline time, ensure that your application download always includes a recently synced realm file. Generate a new file each application version, and ensure that no version ever stays current for more than client maximum offline time number of days.

  1. Create a new project with the same data models as your production app. Open an existing realm with the data you wish to bundle, or create a new one.

  2. Use the WriteCopy() method to make a copy of the realm to a new location and/or name. The following code demonstrates this.

Now that you have a copy of the realm with the "seed" data in it, you need to bundle it with your production application. The process of bundling depends on whether you are building a mobile app or Unity app:

Note

Cross-Platform Compatibility

Non-encrypted realm files are cross-platform compatible, which is why you can bundle the file in the shared project.

Now that you have a copy of the realm included with your app, you need to add code to use it. The code you add depends on the type of app:

←  Delete a Realm - .NET SDKReduce Realm File Size - .NET SDK →