我已经在 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/