如何重启应用(反应本机和博览会)

时间:2019-08-02 16:05:53

标签: react-native expo

我使用expo,因此无法访问android文件夹。

我想第一次重新启动我的应用程序。我该怎么办?

我使用react-native-restart,但没有扭动,现在出现错误:

  

null不是对象(正在评估'x.default.restart;)

代码:

  componentDidMount() {
    if (I18nManager.isRTL) {
      I18nManager.forceRTL(false);
      RNRestart.Restart();
    }
  }

如何重新启动我的应用?

4 个答案:

答案 0 :(得分:8)

我也遇到了同样的问题,并在某处找到了解决方案。

您可以尝试像这样从0 * * * * /bin/sh -c "yes | /foo/bar/my_command" 使用Updates

expo

答案 1 :(得分:3)

一个月来我遇到了同样的问题,没有任何帮助,所以我开发了一个库来完成此任务,只需使用以下命令即可安装它:

npm i fiction-expo-restart

并将其导入为:

import {Restart} from 'fiction-expo-restart';

,然后当您想要重新启动时,使用:

Restart();

请注意,如果这个答案变旧了,您可以在这里检查库:https://www.npmjs.com/package/fiction-expo-restart

答案 2 :(得分:0)

如果您正在使用react-native-code-push库,则可以使用此库重新启动;

import CodePush from 'react-native-code-push';
CodePush.restartApp();

答案 3 :(得分:0)

import { StatusBar } from "expo-status-bar";
import React from "react";
import { Button, I18nManager, StyleSheet, Text, View } from "react-native";
import * as Updates from "expo-updates";

async function toggleRTL() {
  await I18nManager.forceRTL(I18nManager.isRTL ? false : true);
  await Updates.reloadAsync();
}

export default function App() {
  return (
    <View style={styles.container}>
      <Text>{new Date().toString()}</Text>
      <Text>{I18nManager.isRTL ? "RTL" : "LTR"}</Text>
      <View style={{ marginVertical: 5 }} />
      <Button title="Reload app" onPress={() => Updates.reloadAsync()} />
      <View style={{ marginVertical: 5 }} />
      <Button title="Toggle RTL" onPress={() => toggleRTL()} />
      <StatusBar style="auto" />
    </View>
  );
}

https://github.com/brentvatne/updates-reload/blob/master/App.js 对我来说,这是唯一的工作方式。当我尝试在useEffect中自动重新加载应用程序时-它崩溃了,所以我在一个单独的屏幕上要求用户按按钮重新加载应用程序

相关问题