未找到当前活动。确保当您的应用程序位于前台时调用此方法

Kir*_*rti 8 reactjs react-native expo

使用 expo-splash-screen 和 SplashScreen.preventAutoHideAsync() 会在生产版本和在 expo go 上运行应用程序时引发许多错误。

我在 App.js 中首先调用 PreventAutoHideAsync。警告消息是未找到当前活动。确保当您的应用程序位于前台时调用此方法。 https://github.com/expo/expo/issues/20502

按照https://docs.expo.dev/versions/v46.0.0/sdk/splash-screen/实施 可重现的演示: https: //github.com/kirtikapadiya/SplashReactNative

Nor*_*ldt 1

我不确定这是否有效,但我有同样的问题并且会尝试:

// Keep the splash screen visible while we fetch resources
SplashScreen.preventAutoHideAsync().catch((error) => {
  // Attach the event to error handling system (Sentry, LogRocket etc.)

  // Try to call it again when app state is 'active'
  let attempts = 0
  const appStateListener = AppState.addEventListener('change', (nextAppState) => {
    if (nextAppState === 'active' && attempts < 0) {
      attemps++
      SplashScreen.preventAutoHideAsync()
        .then(() => appStateListener.remove())
        .catch((error) => {
          // Attach the event to error handling system (Sentry, LogRocket etc.)
        })
    }
    if (attempts >= 3) {
      appStateListener.remove()
    }
  })
})


export default function App() {
  ....
Run Code Online (Sandbox Code Playgroud)