Implementing App Update Prompts with Firebase Remote Config in React Native

Updating your app is crucial for delivering the best user experience and ensuring security. However, forcing users to update can sometimes be inconvenient. A smart approach is to provide conditional update prompts, allowing users to skip non-mandatory updates. There are many ways to add force update prompts into React Native applications, but In this blog, we’ll explore how we can implement this feature in a React Native app using Firebase Remote Config.

Why Use Firebase Remote Config?

Firebase Remote Config allows you to change the behavior and appearance of your app without requiring users to download an update from the app store. This makes it an ideal tool for managing app updates dynamically.

Related read: A Comprehensive Guide to React Native Firebase Remote Config

Prerequisites

Before getting started, you will need the following to add Firebase Remote Config to your project:

  • A React Native project set up.
  • Firebase should be configured in your project. If not then follow the Firebase setup guide from here.

1. Install Firebase Remote Config

First, install the necessary Firebase packages:

npm install @react-native-firebase/app @react-native-firebase/remote-config

Then navigate into the ios directory and install pods using the following command:

pod install

2. Configure Remote Config

Navigate to the Remote Config option in your Firebase project. There add the following parameters:

  • app_version: The app version that is required. If installed devices have a version less than this, they will get a force update prompt.
  • is_update_mandatory: A boolean param indicating whether the update is mandatory or not.

Set default values for app_version and is_mandatory_update according to your needs. Here is the Firebase Remote Config dashboard:

Firebase-remote-config-dashboard

Secure Your App by Ensuring Timely Updates for Users!

3. Fetch and Activate Config Values

Fetch the latest Remote Config values and activate them using the following code:

remoteConfig()
  .fetchAndActivate()
  .then(fetchedRemotely => {
    if (fetchedRemotely) {
       console.log('Remote configs fetched');
    }  else {
       console.log(‘Remote configs not fetched ');
    }
});

When you are working on the development and testing phase then you want to see your changes immediately. In that scenario you need to update the Firebase Remote Config setting using the following code:

remoteConfig().setConfigSettings({
  minimumFetchIntervalMillis: 0,
});

It is not recommended to set the fetch interval to 0 on Production because it can increase the load by making frequent calls to the Firebase Remote Config.

4. Implement Smart Update Logic

Compare the installed app version with the remote config parameter app_version and check the is_update_mandatory flag. If the installed app’s current version is lower and the update is mandatory, prompt the user to update the app without an option to skip.

If the update is not mandatory, provide a skip option and if the installed app version is the same as the app_version parameter then there will be no prompt for app update.

import { Alert, Linking } from 'react-native';
import VersionCheck from 'react-native-version-check';

const checkForUpdate = async () => {
 const latestVersion = remoteConfig().getValue(app_version');
 const isMandatoryUpdate = remoteConfig().getValue('is_update_mandatory');
 const currentVersion = VersionCheck.getCurrentVersion();

 if (VersionCheck.needUpdate({ currentVersion, latestVersion })) {
  if (isMandatoryUpdate) {
   Alert.alert(
    'Update Available',
    'Please update to continue.',
    [
      { text: 'Update', onPress: () => Linking.openURL('your-app-store-url') },
    ],
    { cancelable: false }
   );
  } else {
  Alert.alert(
   'Update Available',
   'Would you like to update now?',
    [
     { text: 'Update', onPress: () => Linking.openURL('your-app-store-url') },
     { text: 'Skip', style: 'cancel' },
    ]
   );
  }
 }
};

checkForUpdate();
coma

Conclusion

By following these steps, you can implement a smart update prompt in your React Native App, ensuring users are always on the latest version while providing flexibility for non-mandatory updates. Firebase Remote Config offers a powerful way to manage app updates dynamically, enhancing user experience and maintaining app security.

Keep Reading

Keep Reading

Enhance Your Epic EHR Expertise in Just 60 Minutes!

Register Here
  • Service
  • Career
  • Let's create something together!

  • We’re looking for the best. Are you in?