使用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
我不确定这是否会起作用,但我有同样的问题,并将尝试:
// 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() {
....