【问题标题】:react-native app update alert code fails to update appreact-native 应用程序更新警报代码无法更新应用程序
【发布时间】:2021-11-27 23:32:47
【问题描述】:

我开发了一个 react-native 应用程序,目前正在运行(在 Apple 和 Google Play 商店中)。昨晚我使用 react-native-version-check、Alert、backHandler 和 Linking 实现了一个早该实现的功能,更新警报和更新程序。从这个 Medium 博客链接中,我将该功能改编到我的应用程序中并在 Android 上进行了测试。我在商店发布之前测试了我的本地版本代码/版本名称,并且它通过不触发来工作 - 工作。但是,当我回滚我的版本低于商店的版本并重新构建时,它会正确触发一个警报框和“更新”按钮,当单击该按钮时应用程序关闭并且没有其他任何反应。所以我确实看到发生了正确的触发,但更新功能没有。重复多次(点击应用程序,点击更新按钮,应用程序关闭,我收到一条错误消息,显示“您的 Americana Radio 一直在停止”错误。“Your Americana Radio”是我的应用程序名称。

中篇文章/博客: https://medium.com/@kinley.tshering/force-update-react-native-apps-a9c1f22c0701

我的 app.android.js 中的代码专门针对这个函数如下:

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

const checkVersion = async () => {
    try {
        let updateNeeded = await VersionCheck.needUpdate();
        if(updateNeeded && updateNeeded.isNeeded) {
            Alert.alert (
              'Please update',
              'You will have to update this app to the latest version to continue using it.',
              [
                {
                   text: 'Update',
                   onPress: () => {
                                    BackHandler.exitApp();
                                    console.log("-I-: Doing the Update App functions");
                                    Linking.openURL(updateNeeded.storeURL);
                   },
                  },
               ],
               {cancelable: false},
            );
       }
    } catch (error) {};
};
export default function App() {

// React Native Splash Screen
// Ref: https://dev.to/cmcodes/how-to-add-splash-screen-in-a-react-native-android-app-287l
//
// useEffect(() => {
//     SplashScreen.hide();
// }, []); // Splash

const [hideSplash, setHideSplash] = useState(false);

useEffect(() => {
  setTimeout(() => {
    setHideSplash(true);
  }, 2500); // amount of time the splash is shown from the time component is rendered
}, []);

useEffect(() => {
  hideSplash && SplashScreen.hide();
}, [hideSplash]);  // Splash with timer

useEffect(() => {
    checkVersion();
}, []);

  return(
      <SocketContext.Provider value={socket}>
          <AppContainer />
       </SocketContext.Provider >
  )
}

【问题讨论】:

    标签: javascript android react-native


    【解决方案1】:

    这是一个“驾驶舱错误”的案例。
    我一意识到就解决了这个问题

    • 我有updateNeeded.storeURL
    • 而不是updateNeeded.storeUrl

    更改后,代码按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-24
      相关资源
      最近更新 更多