react-native - 如何强制用户使用 React Native 更新应用程序

标签 react-native expo

我已经在 app 和 Play 商店更新了我的应用程序,我想强制我的应用程序用户在 App Store 和 Playstore 更新新版本的应用程序。

最佳答案

您可以使用此库检查应用程序的 App Store/Play Store 版本
react-native-appstore-version-checker .

在 expo 应用程序中,您可以使用 Constants.nativeAppVersion 获取当前的捆绑版本. docs .

现在在你的 root react native 组件中,你可以添加一个事件监听器来检测应用程序状态变化。每次应用程序从后台转换到前台时,您都可以运行您的逻辑来确定当前版本和最新版本,并提示用户更新应用程序。

 import { AppState } from 'react-native';


 class Root extends Component {

   componentDidMount() {
     AppState.addEventListener('change', this._handleAppStateChange);
   }



   _handleAppStateChange = (nextState) => {
     if (nextState === 'active') {

        /**
                Add code to check for the remote app version.
                Compare it with the local version. If they differ, i.e.,
                (remote version) !== (local version), then you can show a screen,
                with some UI asking for the user to update. (You can probably show
                a button, which on press takes the user directly to the store)
         */


     }
    }



   componentWillUnmount() {
      AppState.removeEventListener('change', this._handleAppStateChange);

   }

}

关于react-native - 如何强制用户使用 React Native 更新应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58579903/

相关文章:

javascript - 在键盘感知 ScrollView 中输入文本后按下 React-Native 按钮

javascript - "Cannot connect to the Metro server"在 React-Native/Expo 项目上

javascript - 捆绑失败意外的 token native react

javascript - 如何在一个文件中使用不同字体(不止一种)的 react-native-vector-icons?

react-native - GraphQL DynamoDB 架构中的默认主键?

javascript - React Native 如何更改 secureTextEntry 输入的大小和颜色

javascript - react native (博览会) WebView 错误 net::ERR_CACHE_MISS

react-native - 更改导航标题背景颜色

azure - 无法将 expo 重定向 Uri 添加到 Azure AD B2C 应用程序

Laravel Expo 推送通知 - 在 Android 上未收到通知